~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Marius Kruger
  • Date: 2008-10-01 16:39:00 UTC
  • mto: This revision was merged to the branch mainline in revision 228.
  • Revision ID: amanic@gmail.com-20081001163900-mpj2oj16oic7loh6
nest try to be python2.4 compatible again

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
 
19
19
import logging
 
20
import logging.handlers
20
21
from optparse import OptionParser
21
22
import os
22
23
import sys
23
24
import urlparse
24
25
 
25
 
from bzrlib.plugin import load_plugins
26
 
from bzrlib.util.configobj.configobj import ConfigObj
 
26
from configobj import ConfigObj
27
27
 
28
28
from paste import httpserver
29
29
from paste.httpexceptions import make_middleware
31
31
 
32
32
from loggerhead import daemon
33
33
from loggerhead.apps.config import Root
34
 
from loggerhead.trace import setup_logging
 
34
from loggerhead.trace import make_handler, setup_logging
35
35
from loggerhead.apps.error import ErrorHandlerApp
36
36
 
37
 
 
38
37
def main():
39
38
    home = os.path.realpath(os.path.dirname(__file__))
40
39
    default_pidfile = os.path.join(home, 'loggerhead.pid')
41
40
    default_configfile = os.path.join(home, 'loggerhead.conf')
42
41
    default_log_folder = os.path.join(home, 'logs')
43
42
    parser = OptionParser(usage='usage: %prog [options]', version='%prog')
44
 
    parser.add_option('-f', '--foreground',
45
 
                      action='store_true', dest='foreground', default=False,
 
43
    parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
46
44
                      help="run in the foreground; don't daemonize")
47
 
    parser.add_option('-C', '--check', action='store_true',
48
 
                      dest='check', default=False,
49
 
                      help=("only start if not already running (useful for "
50
 
                            "cron jobs)"))
51
 
    parser.add_option('-p', '--pidfile', dest="pidfile",
52
 
                      default=default_pidfile,
 
45
    parser.add_option('-C', '--check', action='store_true', dest='check', default=False,
 
46
                      help="only start if not already running (useful for cron jobs)")
 
47
    parser.add_option('-p', '--pidfile', dest="pidfile", default=default_pidfile,
53
48
                      type=str, help="override pidfile location")
54
 
    parser.add_option('-c', '--config-file', dest="configfile",
55
 
                      default=default_configfile,
56
 
                      type=str, help="override configuration file location")
57
 
    parser.add_option('-L', '--log-folder', dest="log_folder",
58
 
                      default=default_log_folder,
 
49
    parser.add_option('-c', '--config-file', dest="configfile", default=default_configfile,
 
50
                                          type=str, help="override configuration file location")
 
51
    parser.add_option('-L', '--log-folder', dest="log_folder", default=default_log_folder,
59
52
                      type=str, help="override log file directory")
60
53
    options, args = parser.parse_args()
61
54
    if len(args) > 0:
64
57
    if options.check:
65
58
        if daemon.is_running(options.pidfile):
66
59
            sys.exit(0)
67
 
        sys.stderr.write('Did not find loggerhead running in %r;' % (
68
 
                         options.pidfile))
69
 
        sys.stderr.write(' restarting...\n')
 
60
        sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (options.pidfile,))
70
61
 
71
62
    # read loggerhead config
72
63
 
75
66
    if extra_path:
76
67
        sys.path.insert(0, extra_path)
77
68
 
78
 
    potential_overrides = [('server.socket_port', int),
79
 
                           ('server.webpath', str),
80
 
                           ('server.thread_pool', int),
81
 
                           ('server.socket_host', str)]
 
69
    potential_overrides = [ ('server.socket_port', int),
 
70
                            ('server.webpath', str),
 
71
                            ('server.thread_pool', int),
 
72
                            ('server.socket_host' ,str) ]
82
73
    server_port = int(config.get('server.socket_port', 8080))
83
74
    nworkers = int(config.get('server.thread_pool', 10))
84
75
    server_host = config.get('server.socket_host', '0.0.0.0')
92
83
    if not options.foreground:
93
84
        sys.stderr.write('\n')
94
85
        sys.stderr.write('Launching loggerhead into the background.\n')
95
 
        sys.stderr.write('PID file: %s\n' % options.pidfile)
 
86
        sys.stderr.write('PID file: %s\n' % (options.pidfile,))
96
87
        sys.stderr.write('\n')
97
88
 
98
89
        daemon.daemonize(options.pidfile, home)
111
102
 
112
103
    if webpath:
113
104
        scheme, netloc, path, blah, blah, blah = urlparse.urlparse(webpath)
114
 
 
115
105
        def app(environ, start_response, orig=app):
116
106
            environ['SCRIPT_NAME'] = path
117
107
            environ['HTTP_HOST'] = netloc
118
 
            environ['wsgi.url_scheme'] = scheme
119
108
            return orig(environ, start_response)
120
109
 
121
 
    load_plugins()
122
 
 
123
110
    try:
124
111
        httpserver.serve(
125
112
            app, host=server_host, port=server_port,