Timed Systemd Service Restarts
Timed Systemd Service Restarts
If you have ever wanted to do periodic restarts of a service, and for whatever reason you dont
want to use cron, you can use systemd to accomplish that task.
Systemd has numerous knobs and you can do this task in several different ways. Heres one that
I got to work for me:
Concept
Create a two hour timer which activates a target every two hours. Our target is a one-shot service
which restarts the main service.
two-hour.timer
[Unit]
Description=2hour timer
[Timer]
OnBootSec=0min
OnCalendar=0/2:00:00
Unit=two-hour.service
[Install]
WantedBy=basic.target
two-hour.service
[Unit]
Description=Service that restarts my spread_goodness.service every two hours.
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl try-restart spread_goodness.service