~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to start-loggerhead

  • Committer: Jelmer Vernooij
  • Date: 2008-08-06 18:25:44 UTC
  • mto: (197.1.9 pathargs)
  • mto: This revision was merged to the branch mainline in revision 202.
  • Revision ID: jelmer@samba.org-20080806182544-pgps44xpixond3xd
Add --pidfile argument to start-loggerhead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
 
77
77
 
78
78
def main():
 
79
    home = os.path.realpath(os.path.dirname(__file__))
 
80
    default_pidfile = os.path.join(home, 'loggerhead.pid')
79
81
    parser = OptionParser(usage='usage: %prog [options]', version='%prog ' + release.version)
80
82
    parser.add_option('-f', '--foreground', action='store_true', dest='foreground', default=False,
81
83
                      help="run in the foreground; don't daemonize")
82
84
    parser.add_option('-C', '--check', action='store_true', dest='check', default=False,
83
85
                      help="only start if not already running (useful for cron jobs)")
 
86
    parser.add_option('-p', '--pidfile', dest="pidfile", default=default_pidfile,
 
87
                      help="override pidfile location")
84
88
    options, args = parser.parse_args()
85
89
    if len(args) > 0:
86
90
        parser.error('No filename arguments are used, only options.')
87
91
 
88
 
 
89
 
    home = os.path.realpath(os.path.dirname(__file__))
90
 
    pidfile = os.path.join(home, 'loggerhead.pid')
91
 
 
92
92
    if options.check:
93
 
        if daemon.is_running(pidfile):
 
93
        if daemon.is_running(options.pidfile):
94
94
            sys.exit(0)
95
 
        sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (pidfile,))
 
95
        sys.stderr.write('Did not find loggerhead running in %r; restarting...\n' % (options.pidfile,))
96
96
 
97
97
    # read loggerhead config
98
98
 
121
121
    if not options.foreground:
122
122
        sys.stderr.write('\n')
123
123
        sys.stderr.write('Launching loggerhead into the background.\n')
124
 
        sys.stderr.write('PID file: %s\n' % (pidfile,))
 
124
        sys.stderr.write('PID file: %s\n' % (options.pidfile,))
125
125
        sys.stderr.write('\n')
126
126
 
127
 
        daemon.daemonize(pidfile, home)
 
127
        daemon.daemonize(options.pidfile, home)
128
128
 
129
129
    setup_logging(home, config, foreground=options.foreground)
130
130
 
151
151
    finally:
152
152
        log.info('Shutdown.')
153
153
        try:
154
 
            os.remove(pidfile)
 
154
            os.remove(options.pidfile)
155
155
        except OSError:
156
156
            pass
157
157