|
From: Barry M. <bar...@gm...> - 2023-10-23 12:57:21
|
On 10/23/23 04:42, Ian Smith wrote: > On a regular basis, the software crashes. Ideally, I would like to > understand why, and eliminate the problem - if that isn't possible, I > would like it to automatically restart on crashing, but I don't know > how to do that, so any help would be appreciated. Ian: I also have crashes – more of the random type than regular, but my sloppy-but-it-generally-works solution may be helpful. I am running Motion on Raspberry Pi’s with one USB camera each, so the commands should be similar as you are running Ubuntu. cron: # Check for loss of an error every 10 minutes */10 * * * * /usr/bin/sh /home/pi/Scripts/Timeout.sh Some extracts from my Timeout file (bash script): #### tail /var/log/syslog | grep "Timeout waiting for hardware interrupt" if [ $? -eq 0 ] then echo "Oh bother said Pooh!" sudo shutdown -r now else echo "Nothing to look at, keep moving...." fi #### ########### tail /var/log/user.log | grep "Watchdog timeout did NOT restart" if [ $? -eq 0 ] then echo "Oh mannnnnn!" sudo shutdown -r now else echo "No problem-o." fi ########### And kind of as a side note: ########### # Recycle Motion when goes off-line # NOTE: at home directory: sudo chown pi:pi Scripts # sudo service motion status | grep Active > $HOME/Scripts/Motion_Status.txt # sudo service motion status | grep Active > /home/pi/Scripts/Motion_Status.txt sudo service motion status | grep Active > /mnt/ramdisk/Motion_Status.txt # Without the grep need to <q>uit manually # tail $HOME/Scripts/Motion_Status.txt | grep running tail /mnt/ramdisk/Motion_Status.txt | grep running if [ $? -eq 0 ] then echo "Motion is running." else echo "WHOA!! Motion has a problem!!" sudo service motion stop sleep 3 sudo service motion start fi ########### Couple of things with that snippet: the use of grep to automatically quit the service inquiry I sometimes found when using ‘sudo service restart motion’ it restarted too quickly. Using the stop, 3 second delay, and the the start worked better. There are more options but I don’t think they’d appreciate me clogging the forum. And yes, the echo’s are a little strange but come in handy for testing (manual run from Terminal). HTH and Good Luck! Barry P.S.: I wrote this off-line and copied in but the script indentions are being retained. |