Script to restart Domoticz if it crashes Topic is solved
Moderator: leecollings
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Script to restart Domoticz if it crashes
This is a good script : http://www.domoticz.com/forum/viewtopic ... 89#p149685
-
- Posts: 616
- Joined: Thursday 10 November 2016 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script to restart Domoticz if it crashes
Hello,
That's this one, named checkDomoticz.sh (under /root):
Code: Select all
#!/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
Code: Select all
# m h dom mon dow command
0,30 * * * * /root/checkDomoticz.sh > /dev/null 2>&1
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script to restart Domoticz if it crashes
hi
im a real newbie with this programming stuff, i really want this restart script to work but i have no idea of how to install this on my raspberry pi.
im a real newbie with this programming stuff, i really want this restart script to work but i have no idea of how to install this on my raspberry pi.
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Script to restart Domoticz if it crashes
Hello dear, can you tell me how to make a schedule for a daily restart domoticz at 0:05
-
- Posts: 82
- Joined: Monday 01 December 2014 13:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: London, UK
- Contact:
Re: Script to restart Domoticz if it crashes
I followed this guide and moved Domoticz startup to systemd, and it restarts automatically on crash now.
https://randomstuffintech.wordpress.com ... -domoticz/
https://randomstuffintech.wordpress.com ... -domoticz/
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Script to restart Domoticz if it crashes
I do not want to check whether Domoticz has crash, I want to restart it at a certain time. Maybe there is a simple solution?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script to restart Domoticz if it crashes
Code: Select all
sudo crontab -e
Code: Select all
44 5 * * * service domoticz restart
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Script to restart Domoticz if it crashes
Thank you very much! You helped me!)waaren wrote: ↑Wednesday 22 May 2019 12:32add this line to the crontabCode: Select all
sudo crontab -e
this will restart domoticz at 05:44 AMCode: Select all
44 5 * * * service domoticz restart
-
- Posts: 49
- Joined: Monday 29 January 2018 7:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script to restart Domoticz if it crashes
Domoticz is not startup after a powerdown of the PI
when i login wit putty and add command
sudo /etc/init.d/domoticz.sh restart
is restart and is running again fine
I have this issue for almost a year now , and hoped a fix will come in the versions..
So i hoped some of you guys can help me..
I found this code interesting, see below. But how can it be triggered , only at start up
When i run this in a crob job it will be triggered every x min, or at a special time
when i login wit putty and add command
sudo /etc/init.d/domoticz.sh restart
is restart and is running again fine
I have this issue for almost a year now , and hoped a fix will come in the versions..
So i hoped some of you guys can help me..
I found this code interesting, see below. But how can it be triggered , only at start up
When i run this in a crob job it will be triggered every x min, or at a special time
#!/bin/bash
CONFIG=/home/pi/domoticz/scripts/domoticz_state_checker.txt
dt=$(date '+%d/%m/%Y %H:%M:%S')
DomoticzState=`sudo service domoticz.sh status`
if [[ $DomoticzState == *"active (running)"* ]]
then
echo "Domoticz is running. Nothing to do."
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo "$dt, Domoticz is not running. Restarting Domoticz..." >> "$CONFIG"
sudo service domoticz.sh restart
echo "$dt, Domoticz restarted..." >> "$CONFIG"
fi
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script to restart Domoticz if it crashes
in crontab you could use
Code: Select all
@reboot sleep 180 && /etc/init.d/domoticz.sh restart
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 49
- Joined: Monday 29 January 2018 7:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Script to restart Domoticz if it crashes
Thx @waaren
Tjee that easy, i will add this in the crontab
Tjee that easy, i will add this in the crontab
-
- Posts: 31
- Joined: Friday 08 February 2019 8:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Script to restart Domoticz if it crashes
Hi,K3rryBlue wrote: ↑Friday 10 March 2017 21:06 This one works for the pi, needed to make more changes then expected.Code: Select all
#!/bin/bash dt=$(date '+%d/%m/%Y %H:%M:%S') CONFIG=/home/pi/domoticz/scripts/bash/domoticz_state_checker.txt STATUS=`curl -s --connect-timeout 2 --max-time 5 "Accept: application/json" "http://192.168.1.109:8080/json.htm?type=devices&rid=1" | grep "status"| awk -F: '{print $2}'|sed 's/,//'| sed 's/\"//g'` if [ $STATUS ] ; then exit else sleep 5 STATUS2=`curl -s --connect-timeout 2 --max-time 5 "Accept: application/json" "http://192.168.1.109:8080/json.htm?type=devices&rid=1" | grep "status"| awk -F: '{print $2}'|sed 's/,//'| sed 's/\"//g'` if [ $STATUS2] ; then exit else sleep 5 STATUS3=`curl -s --connect-timeout 2 --max-time 5 "Accept: application/json" "http://192.168.1.109:8080/json.htm?type=devices&rid=1" | grep "status"| awk -F: '{print $2}'|sed 's/,//'| sed 's/\"//g'` if [ $STATUS3 ] ; then exit else NOW=$(date +"%Y-%m-%d_%H%M%S") sudo service domoticz.sh stop sleep 8 sudo killall domoticz sleep 8 sudo service domoticz.sh start echo "$dt, Domoticz was offline. Restarted Domoticz...." >> "$CONFIG" fi fi fi
So I used this version for my pi
I can launch the script without errors, but is it not supposed to write in a log something ?
Or maybe it will just write if a restart occured ?
And finally you just have to add this script in the crontab ?
Many thanks !
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script to restart Domoticz if it crashes
Code: Select all
Only when it tried to restart domoticz it will write a line in /home/pi/domoticz/scripts/bash/domoticz_state_checker.txt
You first need to create directory /home/pi/domoticz/scripts/bash
YesAnd finally you just have to add this script in the crontab ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 31
- Joined: Friday 08 February 2019 8:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Script to restart Domoticz if it crashes
Is there a special need to have the log file under /scripts/bash, or can I put it just in /scripts ?waaren wrote: ↑Thursday 19 December 2019 7:00Code: Select all
Only when it tried to restart domoticz it will write a line in /home/pi/domoticz/scripts/bash/domoticz_state_checker.txt
You first need to create directory /home/pi/domoticz/scripts/bash
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Script to restart Domoticz if it crashes
No you can put it anywhere you like. Of course you need to have enough access rights to write in the directory of choice.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 31
- Joined: Friday 08 February 2019 8:35
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Script to restart Domoticz if it crashes
OK Many thanks !
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Script to restart Domoticz if it crashes
Make a new file, for example /home/pi/checkdomoticz.sh and add this code:
install jq
set the file as executable with
add it to crontab as indicated in the script.
Of course, alter ip/port if needed.
Warning: best to stop the cron service before updating domoticz from the gui.
Code: Select all
#!/bin/bash
: '
crontab -e
# m h dom mon dow command
* * * * * /usr/bin/nice -n20 /home/pi/checkdomoticz.sh >/dev/null 2>&1
'
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS" == "OK" ] ; then
exit
else
sleep 20
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS2=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS2" == "OK" ] ; then
exit
else
sleep 20
DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8080/json.htm?type=devices&rid=1"`
STATUS3=`echo $DOMOTICZ | jq -r '.status'`
if [ "$STATUS3" == "OK" ] ; then
exit
else
service domoticz stop
service domoticz start
#shutdown -r now
fi
fi
fi
Code: Select all
apt install jq
Code: Select all
chmod +x /home/pi/checkdomoticz.sh
Of course, alter ip/port if needed.
Warning: best to stop the cron service before updating domoticz from the gui.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Script to restart Domoticz if it crashes
What is the content of /etc/hosts and /etc/hostname?
Who is online
Users browsing this forum: No registered users and 0 guests