creative-2008
Posts: 58
Joined: Sat Nov 25, 2017 2:16 pm

Restart on Crash

Wed May 01, 2019 8:40 pm

I have my 3B+ running 24/7 as a home server, which I can access from outside my network also when I need to. I've had a Pi running constantly for 18 months and have only had one crash which has led to me needing to pull the plug, and luckily I was home to do it.

Is there anything I can do in terms of forcing it to reboot if it crashes, or automatically rebooting once a week? The reason that I ask is that I'm frequently away for a few weeks at a time, and it would be a bit inconvenient / frustrating if it were to crash at the beginning of my trip and be unavailable throughout.

(I think I may be asking a bit much here, but am open to anything that anyone has to suggest.)

MrEngman
Posts: 3804
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Restart on Crash

Wed May 01, 2019 9:24 pm

There's a item called watchdog that you can use to restart your Pi.

I've no idea myself how to use it but there's plenty of stuff about it in the forum. Just search for "watchdog".

MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

PhatFil
Posts: 1175
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Restart on Crash

Thu May 02, 2019 12:47 am

Belt n braces crash recovery is done this end with a smart wifi switch that toggles its power state off/on on loss of connection with its mqtt broker (the Pi).

The crontab command will invoke an edit of the cron job file http://www.simsalabim-solutions.net/vad ... _job_on_pi

klricks
Posts: 6357
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Restart on Crash

Thu May 02, 2019 12:59 am

One option is to get an IP power switch which will allow you to power off/on things via Internet.

Another option is to use a programmable appliance/light timer with battery backup. https://www.harborfreight.com/digital-timer-95205.html
Then use a shutdown command to safely halt the RPi just before the timer cuts power the the RPi.

For example set the timer to turn off power at 00:00 and then restore power at 00:05.
Issue this command in rc.local or autostart so that the command is run on each boot.

Code: Select all

sudo shutdown -h 23:45
This will safely shut the RPi down at 23:45 then reboot at 00:05 or whatever times you choose.

Longer duration can be achieved by using the +m (minutes) function like this:
(Shutdown in 7 days from now)

Code: Select all

sudo shutdown -h 10080 +m
Note that if using the +m method you will need to shutdown the RPi from the command line just before timer shutdown in order to sync up with the timer:
Use the following to cancel a pending shutdown:

Code: Select all

sudo shutdown -c 
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

creative-2008
Posts: 58
Joined: Sat Nov 25, 2017 2:16 pm

Re: Restart on Crash

Fri May 03, 2019 3:36 pm

Thanks for all of the brilliant responses. I think I'm quite looking forward to putting this into place!

Return to “Beginners”