~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Guillermo Gonzalez
  • Date: 2008-09-26 12:48:00 UTC
  • mfrom: (217.2.2 logging)
  • mto: This revision was merged to the branch mainline in revision 226.
  • Revision ID: guillo.gonzo@gmail.com-20080926124800-7pjmc08s1da0cxg8
 merge with mwhudson logging branch

Show diffs side-by-side

added added

removed removed

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