r/linux_programming • • Sep 07 '19
Script to auto restart services (Sabnzbd, Sonarr, Radarr) when they drop out
I just finished migrating my download server over to a Raspberry Pi 3. I have my Gdrive setup and everything is working as far as the downloading and uploading of my content, my issues is when I wake up in the morning sometimes the apps mentioned in the title have dropped out. So at this point I have to either reboot the pi to have them auto start again or ssh in and restart them all individually, can someone here help me setup a script or other method that will monitor these services and when they drop out start again automatically,
4
Upvotes
9
u/Danacus Sep 07 '19
Not sure if your system uses systemd, but if it does, you could use that to create and enable services.
1
u/TheBioto Sep 07 '19
If you want a super lazy way to fix it, set a cron job to restart the pi every couple hours.
1
u/pfp-disciple Sep 08 '19
Are the services still running when the apps are timed out? If not, then you could set up a cron job to check the status and restart it if it's down.
Another option would be to have the cron job attempt to do a small file transfer (or maybe see if the app has a "check network" option) and restart the service on failure.
Of course this feels like reinventing the wheel. I think I recall one of the proclaimed advantages of systemd being keeping services alive (to be fair, other init systems claim similar ability).
1
u/anatolya Sep 19 '19
You can use a service manager like runit, supervisor etc.
0
u/[deleted] Sep 07 '19
[deleted] — view deleted comment