~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Martin Albisetti
  • Date: 2009-06-02 13:46:32 UTC
  • mto: This revision was merged to the branch mainline in revision 364.
  • Revision ID: martin.albisetti@canonical.com-20090602134632-7wcqj1o3k8hu2pet
Add deprecation warning to start-loggerhead

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