summaryrefslogtreecommitdiffstats
path: root/wallace
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-19 16:55:14 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-19 16:55:14 +0100
commit9663ff263d90af9156112f46c9d7b1651664cb0f (patch)
treebfb3862b2ae08b33c04fd77dca2d57a71b8e8c97 /wallace
parent940d3985175be8ba977faf5559800963c81c64d6 (diff)
downloadpykolab-9663ff263d90af9156112f46c9d7b1651664cb0f.tar.gz
Wallace: Add pid file option and make sure we write it out and handle signals
Diffstat (limited to 'wallace')
-rw-r--r--wallace/__init__.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/wallace/__init__.py b/wallace/__init__.py
index c85e0fe..6677613 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -53,7 +53,15 @@ class WallaceDaemon(object):
)
daemon_group.add_option(
- "-p", "--port",
+ "-p", "--pid-file",
+ dest = "pidfile",
+ action = "store",
+ default = "/var/run/wallaced/wallaced.pid",
+ help = _("Path to the PID file to use.")
+ )
+
+ daemon_group.add_option(
+ "--port",
dest = "wallace_port",
action = "store",
default = 10026,
@@ -187,6 +195,8 @@ class WallaceDaemon(object):
pid = 1
if conf.fork_mode:
self.thread_count += 1
+ self.write_pid()
+ self.set_signal_handlers()
pid = os.fork()
if pid == 0:
@@ -421,3 +431,22 @@ class WallaceDaemon(object):
traceback.print_exc()
s.shutdown(1)
s.close()
+
+ def reload_config(self, *args, **kw):
+ pass
+
+ def remove_pid(self, *args, **kw):
+ if os.access(conf.pidfile, os.R_OK):
+ os.remove(conf.pidfile)
+ raise SystemExit
+
+ def set_signal_handlers(self):
+ import signal
+ signal.signal(signal.SIGHUP, self.reload_config)
+ signal.signal(signal.SIGTERM, self.remove_pid)
+
+ def write_pid(self):
+ pid = os.getpid()
+ fp = open(conf.pidfile,'w')
+ fp.write("%d\n" % (pid))
+ fp.close()