~loggerhead-team/loggerhead/trunk-rich

161 by Michael Hudson
don't insist on python 2.4
1
#!/usr/bin/env python
183.2.1 by John Arbash Meinel
Add Copyright information to most files.
2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
"""A script for stopping the loggerhead process."""
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
17
18
import os
19
import sys
197.1.7 by Jelmer Vernooij
Add --pidfile option to stop-loggerhead.
20
from optparse import OptionParser
21
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
22
home = os.path.realpath(os.path.dirname(__file__))
197.1.7 by Jelmer Vernooij
Add --pidfile option to stop-loggerhead.
23
default_pidfile = os.path.join(home, 'loggerhead.pid')
205 by Martin Albisetti
Further cleaning
24
parser = OptionParser(usage='usage: %prog [options]', version='%prog')
197.1.7 by Jelmer Vernooij
Add --pidfile option to stop-loggerhead.
25
parser.add_option('-p', '--pidfile', dest="pidfile", default=default_pidfile,
230.1.1 by Steve 'Ashcrow' Milner
Updated to follow pep8.
26
                  help="override pidfile location")
197.1.7 by Jelmer Vernooij
Add --pidfile option to stop-loggerhead.
27
28
options, args = parser.parse_args()
29
if len(args) > 0:
230.1.1 by Steve 'Ashcrow' Milner
Updated to follow pep8.
30
    parser.error('No filename arguments are used, only options.')
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
31
32
try:
197.1.7 by Jelmer Vernooij
Add --pidfile option to stop-loggerhead.
33
    f = open(options.pidfile, 'r')
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
34
except IOError, e:
329.1.14 by Matt Nordhoff
Always use a tuple in string formatting
35
    print 'Pid file %s not found.' % (options.pidfile,)
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
36
    sys.exit(1)
37
38
pid = int(f.readline())
39
40
try:
41
    os.kill(pid, 0)
42
except OSError, e:
43
    print 'Stale pid file; server is not running.'
44
    sys.exit(1)
45
46
print
329.1.14 by Matt Nordhoff
Always use a tuple in string formatting
47
print 'Shutting down previous server @ pid %d.' % (pid,)
89 by Robey Pointer
fix up dev.cfg so that nobody will ever have to edit it, by letting the
48
print
49
50
import signal
51
os.kill(pid, signal.SIGINT)