Can I configure systemd services to be periodically restarted?
I have a running process that, for various reasons, needs to be restarted once a day. The job is managed with a systemd .service
file, which looks like this
[Unit]
After=network.target
[Service]
ExecStart=
User=
Group=
WorkingDirectory=
Restart=always
[Install]
WantedBy=multi-user.target
and I’ve setup also crontab to run systemctl restart <service>
once a day. I would like to know if there is an option that I can add to my .service file for restarting the service periodically, such that I can have all the configuration in a single file and basically not use crontab anymore.
I think you need systemd timers https://wiki.archlinux.org/title/systemd/Timers
Ah good find! Thank you for the link. I would prefer something that I can configure in the same service file though, if this is possible at all, because my interest it to only have one configuration file. I am already using crontab, and changing from crontab to another configuration file (such as
.timer
) is not really what I’m looking for. I’d like to keep everything inside the same file, if it makes sense.In the manpage[1] I found a couple of options,
RuntimeMaxSec
andWatchdogSec
, but I’ve never used them before and I don’t even understand if they’re really relevant to my question.[1] https://dokk.org/manpages/debian/12/systemd/systemd.service.5.en