~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Jelmer Vernooij
  • Date: 2009-06-02 22:10:00 UTC
  • mto: This revision was merged to the branch mainline in revision 360.
  • Revision ID: jelmer@samba.org-20090602221000-qdrc9hagb5h3w6to
Install the bzr plugin for loggerhead in setup.py.

Show diffs side-by-side

added added

removed removed

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