Script to restart Domoticz if it crashes

All kinds of 'OS' scripts
User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Script to restart Domoticz if it crashes

Post by Egregius » Monday 15 October 2018 17:23



lost
Posts: 198
Joined: Thursday 10 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to restart Domoticz if it crashes

Post by lost » Wednesday 17 October 2018 18:34

RapTile wrote:
Monday 15 October 2018 13:06
I would like to see this script ( if you are still active on the forum ) ;-)
Hello,

That's this one, named checkDomoticz.sh (under /root):
#!/bin/bash
# Check domoticz (from a crontab) is up a restart whole PI if needed...

domoticzUrl=localhost:8080
BN=`basename $0`

httping -c 5 -i 0 -t 1 --ts -v -Wsqg $domoticzUrl

if [ $? -ne 0 ]
then
logger $BN: Domoticz httping-ed KO, retry after 1mn...
sleep 1m
# Retry once
httping -c 5 -i 0 -t 1 --ts -v -Wsqg $domoticzUrl
if [ $? -ne 0 ]
then
logger $BN: Still KO. Get last logs and REBOOT...
tail -n 20 /tmp/domoticz.txt | logger
shutdown -r now
exit 1
else
logger $BN: Retry OK !
fi
else
logger $BN: Domoticz ALIVE !
fi
exit 0
Plus the cron to call it (from root, as shutdown needs root privilege) every 30mn:
# m h dom mon dow command
0,30 * * * * /root/checkDomoticz.sh > /dev/null 2>&1
That runs independent from Domoticz just to check web interface availability... If not, last 20 log lines from Domoticz (need to activate it, mine logs to /tmp in ram tmpfs) are sent to syslog (for post-mortem info, as /var/log is still on SD card on my system) and PI is rebooted.

RapTile
Posts: 58
Joined: Saturday 10 March 2018 3:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script to restart Domoticz if it crashes

Post by RapTile » Sunday 21 October 2018 19:21

lost wrote:
Wednesday 17 October 2018 18:34
<..>
Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests