8234.1.2
by Gary Poster
checkpoint: this initial buildout variant has several parts working, including run, start, stop, and harness. |
1 |
#!../bin/py
|
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
2 |
|
3 |
# Copyright 2004-2005 Canonical Ltd. All rights reserved.
|
|
5863.9.4
by Curtis Hovey
Changes per lint. |
4 |
# This module uses relative imports.
|
5 |
# pylint: disable-msg=W0403
|
|
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
6 |
__metaclass__ = type |
7 |
||
5863.9.1
by Curtis Hovey
Updated configs and code to used simple datatypes. Changes may still be needed aftert testing. |
8 |
import os, logging |
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
9 |
from signal import SIGTERM |
10 |
from optparse import OptionParser |
|
5373.2.8
by Barry Warsaw
Solve a few other problems related to staging's Mailman configs. |
11 |
from canonical.config import config |
7035.3.4
by Gary Poster
add missing import change revealed by make run |
12 |
from canonical.lazr.pidfile import get_pid, pidfile_path, remove_pidfile |
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
13 |
from canonical.launchpad.scripts import logger_options, logger |
5373.2.6
by Barry Warsaw
Add a start_mailman and stop_mailman target, and modify killservice.py to be |
14 |
from canonical.launchpad.mailman.runmailman import stop_mailman |
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
15 |
|
16 |
||
8234.1.4
by Gary Poster
test works, nominally; and bin/py is a bit more functional. problems with import warnings are more serious because they cause tests to fail. |
17 |
def main(): |
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
18 |
parser = OptionParser('Usage: %prog [options] [SERVICE ...]') |
19 |
logger_options(parser, logging.INFO) |
|
20 |
(options, args) = parser.parse_args() |
|
21 |
log = logger(options) |
|
22 |
if len(args) < 1: |
|
23 |
parser.error('No service name provided') |
|
24 |
for service in args: |
|
5373.2.8
by Barry Warsaw
Solve a few other problems related to staging's Mailman configs. |
25 |
# Mailman is special, but only stop it if it was launched.
|
5863.9.1
by Curtis Hovey
Updated configs and code to used simple datatypes. Changes may still be needed aftert testing. |
26 |
if service == 'mailman' and config.mailman.launch: |
5373.2.6
by Barry Warsaw
Add a start_mailman and stop_mailman target, and modify killservice.py to be |
27 |
stop_mailman() |
28 |
continue
|
|
6278.1.1
by Barry Warsaw
appserver layer |
29 |
log.debug("PID file is %s", pidfile_path(service)) |
30 |
try: |
|
31 |
pid = get_pid(service) |
|
32 |
except ValueError, error: |
|
33 |
log.error(error) |
|
34 |
continue
|
|
35 |
if pid is not None: |
|
36 |
log.info("Killing %s (%d)", service, pid) |
|
37 |
try: |
|
38 |
os.kill(pid, SIGTERM) |
|
39 |
except OSError, x: |
|
40 |
log.error("Unable to kill %s (%d) - %s", |
|
41 |
service, pid, x.strerror) |
|
42 |
try: |
|
43 |
remove_pidfile(service) |
|
44 |
except OSError: |
|
45 |
pass
|
|
1937
by Canonical.com Patch Queue Manager
[r=jamesh] Common PID file handing module |
46 |
else: |
47 |
log.debug("No PID file for %s", service) |