32
36
from loggerhead import daemon
33
37
from loggerhead.apps.config import Root
34
38
from loggerhead.trace import make_handler, setup_logging
39
from loggerhead.apps.error import ErrorHandlerApp
43
sys.stderr.write('\n\n')
44
sys.stderr.write('WARNING!!! This script has been deprecated by '
45
'serve-branches, and will be removed in the next '
46
'release. Please migrate to serve-branches and report '
47
'any missing features.\n')
48
sys.stderr.write('\n\n')
37
50
home = os.path.realpath(os.path.dirname(__file__))
38
51
default_pidfile = os.path.join(home, 'loggerhead.pid')
39
52
default_configfile = os.path.join(home, 'loggerhead.conf')
40
53
default_log_folder = os.path.join(home, 'logs')
41
54
parser = OptionParser(usage='usage: %prog [options]', version='%prog')
42
parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
55
parser.add_option('-f', '--foreground',
56
action='store_true', dest='foreground', default=False,
43
57
help="run in the foreground; don't daemonize")
44
parser.add_option('-C', '--check', action='store_true', dest='check', default=False,
45
help="only start if not already running (useful for cron jobs)")
46
parser.add_option('-p', '--pidfile', dest="pidfile", default=default_pidfile,
58
parser.add_option('-C', '--check', action='store_true',
59
dest='check', default=False,
60
help=("only start if not already running (useful for "
62
parser.add_option('-p', '--pidfile', dest="pidfile",
63
default=default_pidfile,
47
64
type=str, help="override pidfile location")
48
parser.add_option('-c', '--config-file', dest="configfile", default=default_configfile,
49
type=str, help="override configuration file location")
50
parser.add_option('-L', '--log-folder', dest="log_folder", default=default_log_folder,
65
parser.add_option('-c', '--config-file', dest="configfile",
66
default=default_configfile,
67
type=str, help="override configuration file location")
68
parser.add_option('-L', '--log-folder', dest="log_folder",
69
default=default_log_folder,
51
70
type=str, help="override log file directory")
52
71
options, args = parser.parse_args()
66
87
sys.path.insert(0, extra_path)
68
potential_overrides = [ ('server.socket_port', int),
69
('server.webpath', str),
70
('server.thread_pool', int),
71
('server.socket_host' ,str) ]
89
potential_overrides = [('server.socket_port', int),
90
('server.webpath', str),
91
('server.thread_pool', int),
92
('server.socket_host', str)]
72
93
server_port = int(config.get('server.socket_port', 8080))
73
94
nworkers = int(config.get('server.thread_pool', 10))
74
95
server_host = config.get('server.socket_host', '0.0.0.0')
98
119
app = make_middleware(app)
99
app = make_filter(app, None)
120
app = make_filter(app, None, logger_name=log.name+'.access')
121
app = ErrorHandlerApp(app)
102
124
scheme, netloc, path, blah, blah, blah = urlparse.urlparse(webpath)
103
126
def app(environ, start_response, orig=app):
104
127
environ['SCRIPT_NAME'] = path
105
128
environ['HTTP_HOST'] = netloc
129
environ['wsgi.url_scheme'] = scheme
106
130
return orig(environ, start_response)
109
135
httpserver.serve(
110
136
app, host=server_host, port=server_port,