Changeset View
Changeset View
Standalone View
Standalone View
kolabd/__init__.py
Show All 23 Lines | |||||
import grp | import grp | ||||
import os | import os | ||||
import pwd | import pwd | ||||
import shutil | import shutil | ||||
import sys | import sys | ||||
import time | import time | ||||
import traceback | import traceback | ||||
import multiprocessing | |||||
import pykolab | import pykolab | ||||
from pykolab.auth import Auth | from pykolab.auth import Auth | ||||
from pykolab import constants | from pykolab import constants | ||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.translate import _ as _l | from pykolab.translate import _ as _l | ||||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | class KolabDaemon: | ||||
def remove_pid(self, *args, **kw): | def remove_pid(self, *args, **kw): | ||||
""" | """ | ||||
Remove our PID file. | Remove our PID file. | ||||
Note that multiple processes can attempt to do this very same thing | Note that multiple processes can attempt to do this very same thing | ||||
at the same time, and therefore we need to test if the PID file | at the same time, and therefore we need to test if the PID file | ||||
exists, and only try/except removing it. | exists, and only try/except removing it. | ||||
""" | """ | ||||
if os.access(conf.pidfile, os.R_OK): | |||||
try: | try: | ||||
for p in multiprocessing.active_children(): | |||||
p.terminate() | |||||
if os.access(conf.pidfile, os.R_OK): | |||||
os.remove(conf.pidfile) | os.remove(conf.pidfile) | ||||
except Exception: | except Exception: | ||||
pass | pass | ||||
raise SystemExit | raise SystemExit | ||||
def set_signal_handlers(self): | def set_signal_handlers(self): | ||||
import signal | import signal | ||||
signal.signal(signal.SIGHUP, self.reload_config) | signal.signal(signal.SIGHUP, self.reload_config) | ||||
signal.signal(signal.SIGTERM, self.remove_pid) | signal.signal(signal.SIGTERM, self.remove_pid) | ||||
def write_pid(self): | def write_pid(self): | ||||
pid = os.getpid() | pid = os.getpid() | ||||
fp = open(conf.pidfile, 'w') | fp = open(conf.pidfile, 'w') | ||||
fp.write("%d\n" % (pid)) | fp.write("%d\n" % (pid)) | ||||
fp.close() | fp.close() |