summaryrefslogtreecommitdiffstats
path: root/kolabd
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-09 23:00:30 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-09 23:00:30 +0000
commita5b0049c34e74c5725f31c615254464fe8d61de8 (patch)
tree7cac92ef20f3674bb21a0c128bfe4f18848e2573 /kolabd
parent44169b3a26e74ef4e2dcebd35cdbe938d1f11b90 (diff)
downloadpykolab-a5b0049c34e74c5725f31c615254464fe8d61de8.tar.gz
Add signal handlers to kolabd and saslauthd
Add -p / --pid-file option to these daemons
Diffstat (limited to 'kolabd')
-rw-r--r--kolabd/__init__.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/kolabd/__init__.py b/kolabd/__init__.py
index 56bfe9b..c749ae6 100644
--- a/kolabd/__init__.py
+++ b/kolabd/__init__.py
@@ -34,8 +34,6 @@ import traceback
import pykolab
from pykolab.auth import Auth
-from pykolab.conf import Conf
-from pykolab.imap import IMAP
from pykolab.constants import *
from pykolab.translate import _
@@ -59,6 +57,12 @@ class KolabDaemon(object):
default = False,
help = _("Fork to the background."))
+ daemon_group.add_option( "-p", "--pid-file",
+ dest = "pidfile",
+ action = "store",
+ default = "/var/run/kolabd/kolabd.pid",
+ help = _("Path to the PID file to use."))
+
conf.finalize_conf()
self.thread_count = 0
@@ -77,8 +81,11 @@ class KolabDaemon(object):
if pid == 0:
log.remove_stdout_handler()
-
- self.do_sync()
+ self.write_pid()
+ self.set_signal_handlers()
+ self.do_sync()
+ elif not conf.fork_mode:
+ self.do_sync()
except SystemExit, e:
exitcode = e
@@ -134,3 +141,22 @@ class KolabDaemon(object):
%(primary_domain, (end_time-start_time))
)
domain_auth[primary_domain].synchronize(primary_domain, secondary_domains)
+
+ def reload_config(self):
+ pass
+
+ def remove_pid(self):
+ 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()