From a5b0049c34e74c5725f31c615254464fe8d61de8 Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Wed, 9 Nov 2011 23:00:30 +0000 Subject: Add signal handlers to kolabd and saslauthd Add -p / --pid-file option to these daemons --- saslauthd/__init__.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'saslauthd') diff --git a/saslauthd/__init__.py b/saslauthd/__init__.py index c74b39c..9756c54 100644 --- a/saslauthd/__init__.py +++ b/saslauthd/__init__.py @@ -52,8 +52,16 @@ class SASLAuthDaemon(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 + def run(self): """ Run the SASL authentication daemon. @@ -67,7 +75,10 @@ class SASLAuthDaemon(object): pid = os.fork() if pid == 0: + self.thread_count += 1 log.remove_stdout_handler() + self.set_signal_handlers() + self.write_pid() self.do_saslauthd() elif not conf.fork_mode: self.do_saslauthd() @@ -89,6 +100,7 @@ class SASLAuthDaemon(object): exitcode = 2 traceback.print_exc() print >> sys.stderr, _("Traceback occurred, please report a bug at http://bugzilla.kolabsys.com") + sys.exit(exitcode) def do_saslauthd(self): @@ -108,7 +120,7 @@ class SASLAuthDaemon(object): try: os.remove('/var/run/saslauthd/mux') except: - # TODO: Do the "could not remove, could not start dance" + # TODO: Do the "could not remove, could not start" dance pass s.bind('/var/run/saslauthd/mux') @@ -141,3 +153,22 @@ class SASLAuthDaemon(object): clientsocket.send(struct.pack("!H2s", 2, "NO")) clientsocket.close() + + 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() -- cgit v1.1