13
13
# along with this program; if not, write to the Free Software
14
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
"""A script for starting the loggerhead process."""
17
WARNING! This script has been deprecated and will go away soon!
18
A script for starting the loggerhead process.
20
import logging.handlers
21
23
from optparse import OptionParser
26
from configobj import ConfigObj
28
from bzrlib.plugin import load_plugins
29
from bzrlib.util.configobj.configobj import ConfigObj
28
31
from paste import httpserver
29
32
from paste.httpexceptions import make_middleware
32
35
from loggerhead import daemon
33
36
from loggerhead.apps.config import Root
34
from loggerhead.trace import make_handler, setup_logging
37
from loggerhead.trace import setup_logging
38
from loggerhead.apps.error import ErrorHandlerApp
42
sys.stderr.write('\n\n')
43
sys.stderr.write('WARNING!!! This script has been deprecated by '
44
'serve-branches, and will be removed in the next '
45
'release. Please migrate to serve-branches and report '
46
'any missing features.\n')
47
sys.stderr.write('\n\n')
37
49
home = os.path.realpath(os.path.dirname(__file__))
38
50
default_pidfile = os.path.join(home, 'loggerhead.pid')
39
51
default_configfile = os.path.join(home, 'loggerhead.conf')
40
52
default_log_folder = os.path.join(home, 'logs')
41
53
parser = OptionParser(usage='usage: %prog [options]', version='%prog')
42
parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
54
parser.add_option('-f', '--foreground',
55
action='store_true', dest='foreground', default=False,
43
56
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,
57
parser.add_option('-C', '--check', action='store_true',
58
dest='check', default=False,
59
help=("only start if not already running (useful for "
61
parser.add_option('-p', '--pidfile', dest="pidfile",
62
default=default_pidfile,
47
63
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,
64
parser.add_option('-c', '--config-file', dest="configfile",
65
default=default_configfile,
66
type=str, help="override configuration file location")
67
parser.add_option('-L', '--log-folder', dest="log_folder",
68
default=default_log_folder,
51
69
type=str, help="override log file directory")
52
70
options, args = parser.parse_args()
66
86
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) ]
88
potential_overrides = [('server.socket_port', int),
89
('server.webpath', str),
90
('server.thread_pool', int),
91
('server.socket_host', str)]
72
92
server_port = int(config.get('server.socket_port', 8080))
73
93
nworkers = int(config.get('server.thread_pool', 10))
74
94
server_host = config.get('server.socket_host', '0.0.0.0')
98
118
app = make_middleware(app)
99
app = make_filter(app, None)
119
app = make_filter(app, None, logger_name=log.name+'.access')
120
app = ErrorHandlerApp(app)
102
123
scheme, netloc, path, blah, blah, blah = urlparse.urlparse(webpath)
103
125
def app(environ, start_response, orig=app):
104
126
environ['SCRIPT_NAME'] = path
105
127
environ['HTTP_HOST'] = netloc
128
environ['wsgi.url_scheme'] = scheme
106
129
return orig(environ, start_response)
109
134
httpserver.serve(
110
135
app, host=server_host, port=server_port,