So I have monitor running on two pi’s, which I installed and ran via ssh because I can’t be bothered plugging the pi downstairs into a monitor and the one upstairs, well it’s on my desk but I don’t have a spare screen for it.
I know that when you exit a ssh session it will kill the script, but I don’t want to leave my PC running. I’ve tried using nohup which worked for a time but eventually both scripts stopped. I’m not sure that using screen would be right either or even disown? The command I’m running is sudo bash monitor.sh
Other than attaching both pis to a monitor and starting the script local what is the best way to make sure the script keeps running. I’ve got binary sensors so I can see when they’ve stopped, but it doesn’t help if they’re just going to stop every time I shut down my PC etc.
If you want it running 24/7 look in to adding it as a cronjob.
Start it with @reboot
1 Like
I was actually looking at cron just before I posted! I’ll go back to it. Definitely want the script to start again on reboot
If you installed it correctly it will already have set up a service to start automatically on reboot. Just reboot the pi…
No cron jobs or any other interventions required.
So this is a pi that is on 24/7 - it’s only going to get rebooted if I manually do so. I’d have to schedule a reboot to have the service start again. For instance yesterday, the process stopped half way through the afternoon on one pi, and this morning it stopped on the other one. So I either enforce a reboot or the script to start over? I think…
Ideally you would want to find out why it is failing.
I run two instances on pi zeros here and they work for days on end. I have a script that runs once a week to do various things and at the end of the script it reboots, but that script is a fairly recent addition and I don’t remember needing to reboot them much prior to it.
Today, nothing has stopped. Still going 4 hours after I last checked - maybe yesterday was just a bad day for the pis!
If your system provides systemd, you could create a service-unit for your script. Here are some examples. What might be interesting for you is the Restart option, which would respawn the script when it dies. And as a nice bonus, you have the journal which contains the output of your script, allowing you to figure out why the script is terminating in the first place.
As an update, I ended up using systemd - I have scripts that start each service on reboot. I actually learned these from setting up my plex media server and with your prompt. I also got myself a dummy hdmi thing and so now I can use teamviewer to remote into my media server. I’ve had one or two instances where I’ve needed to restart the script but other than that it’s worked well!
2 Likes