~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Martin Albisetti
  • Date: 2008-12-22 19:33:12 UTC
  • Revision ID: argentina@gmail.com-20081222193312-b5ql8ksk75rqgxbb
Updated NEWS

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