I installed python-daemon and now I'm trying to process the signal correctly. My code is:
#!/usr/bin/env python # -*- coding: utf-8 -*- import signal, time, syslog import daemon def runDaemon(): context = daemon.DaemonContext() context.signal_map = { signal.SIGTERM: programCleanup } context.open() with context: doMainProgram() def doMainProgram(): while True: syslog.syslog("pythonDaemon is running") time.sleep(5) def programCleanup(): syslog.syslog("pythonDaemon STOP") if __name__ == "__main__": runDaemon()
When I run the code, everything works as expected: the pythonDaemon text starts, writes to /var/log/syslog every 5 seconds. But when I want to end the daemon with kill -TERM *PID* , the daemon ends, but pythonDaemon STOP is missing from syslog.
What am I doing wrong?
NB: I do not work from from daemon import runner here because it gives me an error (it seems I need an older version of the lockfile ) and I will not fix it unless this is the only way to get the signal the correct call.
Ocaso protal
source share