I have a daemon which runs for a pre-configured period of time and then quit. User can restart it if needed after that. It seems that systemd cannot handle this type of service. Below is the service file I tried.
[Unit]
# DaemonXXX quits
Description=DaemonXXX
After=network.target
[Service]
Type=forking
PIDFile=/var/run/daemonXXX.pid
ExecStart=/usr/local/sbin/daemonXXX
StandardOutput=journal
[Install]
WantedBy=multi-user.target
I can start service with above unit file. After the daemon quits, I'm also able to start it again by command systemctrl start DaemonXXX
. But when the service quit after timeout, systemd
complains that system is degraded because daemonXXX quits. If I add RemainAfterExit
opton to [Service]
section,
[Unit]
# as above
...
[Service]
# as above
...
RemainAfterExit=yes
...
systemd
will not complain of degrarded
system but I am no longer able to restart the service again by command systemctrl start daemonXXX
as systemd
assumes that daemonXXX
is running correctly and there is no need to restart it. Is there a way to solve it?