I have an old-school daemon that I want to control using systemd. When its configuration file changes, it needs to be killed and restarted. In other words, after editing the config file, systemctl reload MYSERVICE
should kill the process and restart it.
Attempt 1: Try the defaults. This tells systemd how to start the daemon, but not how to reload it.
[Service]
ExecStart=/usr/bin/MYSERVICE
Type=simple
As a result, start
and restart
work, but reload
gives this error:
# systemctl reload MYSERVICE
Failed to reload MYSERVICE.service: Job type reload is not applicable for unit MYSERVICE.service.
Attempt 2: Tell it how to kill the process. This kills the process but systemd doesn't restart it for me.
[Service]
ExecStart=/usr/bin/MYSERVICE
Type=simple
ExecReload=/bin/kill -HUP $MAINPID
...followed by...
# systemctl daemon-reload
# systemctl reload MYSERVICE
...kills the process but it is not restarted automatically.
Attempt 3: Use ExecReload to restart the process too. This fails for a few reasons:
ExecReload=/bin/kill -HUP $MAINPID ; /usr/bin/MYSERVICE
...the error message I get...:
# systemctl daemon-reload
# systemctl reload MYSERVICE
Job for MYSERVICE.service failed because the control process exited with error code. See "systemctl status MYSERVICE.service" and "journalctl -xe" for details.
I would expect there to be a ReloadType=kill_and_restart or something but no such luck.
How to tell systemd to kill and restart a daemon on reload?