Merge lp:~jaypipes/glance/add-pidfile-option into lp:~glance-coresec/glance/cactus-trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Devin Carlen
Approved revision: 72
Merged at revision: 73
Proposed branch: lp:~jaypipes/glance/add-pidfile-option
Merge into: lp:~glance-coresec/glance/cactus-trunk
Prerequisite: lp:~jaypipes/glance/bug719834
Diff against target: 69 lines (+16/-8)
1 file modified
bin/glance-control (+16/-8)
To merge this branch: bzr merge lp:~jaypipes/glance/add-pidfile-option
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Soren Hansen (community) Approve
Rick Harris Pending
Review via email: mp+49929@code.launchpad.net

Commit message

Adds --pid-file option to bin/glance-control

Description of the change

Adds --pid-file option to bin/glance-control

To post a comment you must log in.
Revision history for this message
Soren Hansen (soren) wrote :

lgtm

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/glance-control'
2--- bin/glance-control 2011-02-09 21:59:39 +0000
3+++ bin/glance-control 2011-02-16 08:16:36 +0000
4@@ -24,7 +24,6 @@
5 from __future__ import with_statement
6
7 import errno
8-import glob
9 import os
10 import optparse
11 import resource
12@@ -54,11 +53,14 @@
13 And CONFPATH is the optional configuration file to use."""
14
15
16-def pid_files(server):
17- if os.path.exists('/var/run/glance/%s.pid' % server):
18- pid_files = ['/var/run/glance/%s.pid' % server]
19+def pid_files(server, options):
20+ pid_files = []
21+ if options['pid_file']:
22+ if os.path.exists(os.path.abspath(options['pid_file'])):
23+ pid_files = [os.path.abspath(options['pid_file'])]
24 else:
25- pid_files = glob.glob('/var/run/glance/%s/*.pid' % server)
26+ if os.path.exists('/var/run/glance/%s.pid' % server):
27+ pid_files = ['/var/run/glance/%s.pid' % server]
28 for pid_file in pid_files:
29 pid = int(open(pid_file).read().strip())
30 yield pid_file, pid
31@@ -67,7 +69,7 @@
32 def do_start(server, options, args):
33 server_type = '-'.join(server.split('-')[:-1])
34
35- for pid_file, pid in pid_files(server):
36+ for pid_file, pid in pid_files(server, options):
37 if os.path.exists('/proc/%s' % pid):
38 print "%s appears to already be running: %s" % (server, pid_file)
39 return
40@@ -119,7 +121,10 @@
41 else:
42 write_pid_file(pid_file, pid)
43
44- pid_file = '/var/run/glance/%s.pid' % server
45+ if not options['pid_file']:
46+ pid_file = '/var/run/glance/%s.pid' % server
47+ else:
48+ pid_file = os.path.abspath(options['pid_file'])
49 conf_file = config.find_config_file(options, args)
50 if not conf_file:
51 sys.exit("Could not find any configuration file to use!")
52@@ -137,7 +142,7 @@
53 sig = signal.SIGTERM
54
55 did_anything = False
56- pfiles = pid_files(server)
57+ pfiles = pid_files(server, options)
58 for pid_file, pid in pfiles:
59 did_anything = True
60 try:
61@@ -164,6 +169,9 @@
62 if __name__ == '__main__':
63 oparser = optparse.OptionParser(usage=USAGE, version='%%prog %s'
64 % version.version_string())
65+ oparser.add_option('--pid-file', default=None, metavar="PATH",
66+ help="File to use as pid file. Default: "
67+ "/var/run/glance/$server.pid")
68 config.add_common_options(oparser)
69 (options, args) = config.parse_options(oparser)
70

Subscribers

People subscribed via source and target branches