I have written a small daemon in Python with:
#!/usr/bin/python3
import time
import click
import daemonocle
from daemonocle.cli import DaemonCLI
@click.command(cls=DaemonCLI, daemon_params={'pidfile': '/var/run/daemon.pid'})
def main():
while True:
time.sleep(3)
if __name__ == '__main__':
main()
It works great as is. If I do the following I get a good exit status 0
$ sudo ./daemon start
Starting daemon ... OK
$ echo $?
0
Then I wrote a systemd
service file:
[Unit]
SourcePath=/home/pi/daemon/daemon
Description=My First Daemon
Before=multi-user.target
After=mosquitto.target
[Service]
Type=forking
PIDFile=/var/run/daemon.pid
Restart=no
ExecStart=/home/pi/daemon/daemon start
ExecStop=/home/pi/daemon/daemon stop
ExecReload=/home/pi/daemon/daemon reload
And if I try to run my daemon with systemctl
the command remains blocking:
$ sudo systemctl start daemon
^C
$ sudo systemctl status daemon
? daemon.service - XEMWAY Demo Service
Loaded: loaded (/home/pi/daemon/daemon; static; vendor preset: enabled)
Active: activating (start) since Wed 2019-02-13 13:47:40 GMT; 12s ago
Process: 13044 ExecStop=/home/pi/daemon/daemon stop (code=exited, status=0/SUCCESS)
Main PID: 12304 (code=exited, status=143); Control PID: 13079 (daemon)
CGroup: /system.slice/daemon.service
+-13079 /usr/bin/python3 /home/pi/daemon/daemon start
+-13081 /usr/bin/python3 /home/pi/daemon/daemon start
After one minute systemd
says:
Feb 13 13:49:10 raspberrypi systemd[1]: daemon.service: Unit entered failed state. Feb 13 13:49:10 raspberrypi systemd[1]: daemon.service: Failed with result 'timeout'.
What's wrong with this?