I've been following the this example to implement a python daemon, and it seems to be somewhat working, but only the reconfigure function is called.
This is the code I've been using:
import signal
import daemon
import lockfile
import manager
context = daemon.DaemonContext(
working_directory='/home/debian/station',
pidfile=lockfile.FileLock('/var/run/station.pid'))
context.signal_map = {
signal.SIGTERM: manager.Manager.program_terminate,
signal.SIGHUP: 'terminate',
signal.SIGUSR1: manager.Manager.program_reload_configuration,
}
manager.Manager.program_configure()
with context:
manager.Manager.program_start()
This is the code on the manager class:
@staticmethod
def program_configure():
logging.info('Configuring program')
@staticmethod
def program_reload_configuration():
logging.info('Reloading configuration')
@staticmethod
def program_start():
global Instance
logging.info('Program started')
Instance = Manager()
Instance.run()
@staticmethod
def program_terminate():
logging.info('Terminating')
And the log shows only:
INFO:root:Configuring program
For some reason program_start()
isn't being called.
program_configure()
is called every time the python file is read, so that's that, but why isn't program_start()
called?
I start the daemon by typing sudo service station.sh start
and the line that runs the script is:
python $DAEMON start
EDIT:
After reading a bit, I've realized that the program probably exits or hangs in context.__enter__()
(with
calls that). But I have no clue what is causing this