How to restart service after some time?
Solution 1:
I suggest using cron in this case:
@reboot sleep 300 && systemctl restart yourservice
This should restart your service 5 minutes after the machine has booted
For more information see the Extension section in the crontab(5) manpage https://linux.die.net/man/5/crontab
Solution 2:
Create a .timer unit to control the .service unit.
Use the same base name as the service, so if the service were called thing
, in /etc/systemd/system/foo.timer
[Unit]
Description=Start broken thing twice
[Timer]
OnBootSec=1min
OnBootSec=2min
[Install]
WantedBy=timers.target
Then enable this new timer. systemctl enable thing.timer
As the service remains active even if it has this problem, edit overrides such that it doesn't. systemctl edit thing.service
Which to change is hard to say without seeing the original unit. Perhaps add a ExecStartPost=
command that returns 0 only if the device is in a good state. Or change RemainAfterExit=no
to force a oneshot to not stay active.