~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Toshio Kuratomi
  • Date: 2010-04-18 17:58:04 UTC
  • mto: (464.1.1 mod-wsgi)
  • mto: This revision was merged to the branch mainline in revision 465.
  • Revision ID: toshio@fedoraproject.org-20100418175804-8auslftjigl36lvr
Add GPLv2+ header to loggerhead.wsgi script

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
15
15
 
16
 
"""A script for starting the loggerhead process."""
 
16
"""
 
17
WARNING! This script has been deprecated and will go away soon!
 
18
A script for starting the loggerhead process.
 
19
"""
17
20
 
18
21
 
19
22
import logging
20
 
import logging.handlers
21
23
from optparse import OptionParser
22
24
import os
23
25
import sys
24
26
import urlparse
25
27
 
26
 
from configobj import ConfigObj
 
28
from bzrlib.plugin import load_plugins
 
29
from bzrlib.util.configobj.configobj import ConfigObj
27
30
 
28
31
from paste import httpserver
29
32
from paste.httpexceptions import make_middleware
31
34
 
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
35
38
from loggerhead.apps.error import ErrorHandlerApp
36
39
 
 
40
 
37
41
def main():
 
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')
 
48
 
38
49
    home = os.path.realpath(os.path.dirname(__file__))
39
50
    default_pidfile = os.path.join(home, 'loggerhead.pid')
40
51
    default_configfile = os.path.join(home, 'loggerhead.conf')
41
52
    default_log_folder = os.path.join(home, 'logs')
42
53
    parser = OptionParser(usage='usage: %prog [options]', version='%prog')
43
 
    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,
44
56
                      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,
 
57
    parser.add_option('-C', '--check', action='store_true',
 
58
                      dest='check', default=False,
 
59
                      help=("only start if not already running (useful for "
 
60
                            "cron jobs)"))
 
61
    parser.add_option('-p', '--pidfile', dest="pidfile",
 
62
                      default=default_pidfile,
48
63
                      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,
 
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,
52
69
                      type=str, help="override log file directory")
53
70
    options, args = parser.parse_args()
54
71
    if len(args) > 0:
57
74
    if options.check:
58
75
        if daemon.is_running(options.pidfile):
59
76
            sys.exit(0)
60
 
        sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (options.pidfile,))
 
77
        sys.stderr.write('Did not find loggerhead running in %r;' % (
 
78
                         options.pidfile))
 
79
        sys.stderr.write(' restarting...\n')
61
80
 
62
81
    # read loggerhead config
63
82
 
66
85
    if extra_path:
67
86
        sys.path.insert(0, extra_path)
68
87
 
69
 
    potential_overrides = [ ('server.socket_port', int),
70
 
                            ('server.webpath', str),
71
 
                            ('server.thread_pool', int),
72
 
                            ('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)]
73
92
    server_port = int(config.get('server.socket_port', 8080))
74
93
    nworkers = int(config.get('server.thread_pool', 10))
75
94
    server_host = config.get('server.socket_host', '0.0.0.0')
102
121
 
103
122
    if webpath:
104
123
        scheme, netloc, path, blah, blah, blah = urlparse.urlparse(webpath)
 
124
 
105
125
        def app(environ, start_response, orig=app):
106
126
            environ['SCRIPT_NAME'] = path
107
127
            environ['HTTP_HOST'] = netloc
 
128
            environ['wsgi.url_scheme'] = scheme
108
129
            return orig(environ, start_response)
109
130
 
 
131
    load_plugins()
 
132
 
110
133
    try:
111
134
        httpserver.serve(
112
135
            app, host=server_host, port=server_port,