Page 2 of 10
Re: Script to restart Domoticz if it crashes
Posted: Monday 19 December 2016 21:39
by jannl
I test if domoticz is running by issuing a json call. The status of the service might be ok even if domoticz hangs.
Re: Script to restart Domoticz if it crashes
Posted: Wednesday 04 January 2017 9:52
by adjego
I also have this happening.
Jan 3 23:22:00 raspberrypi domoticz: Error: /home/pi/domoticz/domoticz() [0x1a9650]
Jan 3 23:22:00 raspberrypi domoticz: Error: /home/pi/domoticz/domoticz(_Z14signal_handleri+0x58) [0x1a9708]
Jan 3 23:22:00 raspberrypi domoticz: Error: /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0x76b9eb20]
Jan 3 23:22:00 raspberrypi domoticz: Error: /lib/arm-linux-gnueabihf/libc.so.6(gsignal+0x40) [0x76b9d8dc]
Is there an actual fix for this issue?
I now have the script in place, but it's a workaround, not a fix.
@jannl, can you share your script?
Re: Script to restart Domoticz if it crashes
Posted: Wednesday 04 January 2017 9:57
by jannl
Basically the script I use is in the wiki:
https://www.domoticz.com/wiki/Monitoring_domoticz
I only tweaked the curl parameters a little bit to include a timeout
Re: Script to restart Domoticz if it crashes
Posted: Wednesday 04 January 2017 15:08
by spikehome
tjabas wrote:Im really new to this Linux and rasberry, but how do i install this script?
I have lot of problems with Domoticz freezing, so i guess this script would do the trick.
I had the problem also.
Installed new and restored the db.
Now it is working fine for a week (normaly in a few days web and ssh not accessible).
Re: Script to restart Domoticz if it crashes
Posted: Monday 23 January 2017 20:27
by philchillbill
The script works by checking the text that results from running the command: sudo service domoticz.sh status
The rpi version of Linux replies with a slightly different text that e.g. Ubuntu: 'domoticz is running' vs 'active (running)'.
If the version of the script you are using is checking for the wrong text it will never find it. Please look carefully at the earlier examples above and watch out for these differences I just mentioned.
Re: Script to restart Domoticz if it crashes
Posted: Saturday 28 January 2017 9:26
by hansrune
I use another approach, i.e a healthcheck script that runs from cron to check on port listeners, network connectivity and more.
Reboots on some conditions, restarts Domoticz if no listener for that network port. I chose to not restart services if someone is logged in to a shell, assuming that I me doing some maintenance.
You can pick this up, or perhaps use some ideas from
https://github.com/hansrune/domoticz-co ... lthchkdomo
Instruction in the beginning....
Re: Script to restart Domoticz if it crashes
Posted: Monday 06 March 2017 9:19
by K3rryBlue
Made a small change to this script. As the status response changed:
Code: Select all
#!/bin/bash
DomoticzState=`sudo service domoticz.sh status`
if [[ $DomoticzState == *"active (running)"* ]]
then
echo 'Domoticz is running. Nothing to do.'
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz.sh restart
echo 'Domoticz restarted.'
fi
Re: Script to restart Domoticz if it crashes
Posted: Monday 06 March 2017 9:38
by Egregius
I believe it's better to query the json API to check that domoticz is online.
Because:
a) A service might be running but hanging and thus give a false response
b) A port might be listening but the service behind it hangs, again false response.
Re: Script to restart Domoticz if it crashes
Posted: Monday 06 March 2017 10:06
by oohlaf
If it's just to check when domoticz has crashed (ie exited) and if your system uses systemd, then use the following:
(change the execstart parameters to your own usage)
Code: Select all
[Unit]
Description=Domoticz Home Automation
After=network.target
[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi/domoticz
PIDFile=/var/run/domoticz/domoticz.pid
ExecStart=/home/pi/domoticz/domoticz -daemon -pidfile /var/run/domoticz/domoticz.pid -www 8080 -sslwww 0 -log /var/log/domoticz/domoticz.log
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Alias=domoticz.sh.service
Re: Script to restart Domoticz if it crashes
Posted: Monday 06 March 2017 22:34
by K3rryBlue
Yes, there are indeed better, or multiple, ways but so far the simple script does what it needs to do.
However i must admit, that lately, the pi runs very stable, by using berryboot and run everything from a USB thumb. teh sd-card is only used to boot the rPi. So far Domoticz is stable for 2 weeks, no "database malfunctions" or crashes.
Cause the rPi runs stable now, it revealed a new problem, with OpenZWave + RazBerry2. Need to figure a way to detect that ZWave is not responding anymore, probably via a JSON call. IF no response THEN reboot rPi.
Re: Script to restart Domoticz if it crashes
Posted: Tuesday 07 March 2017 1:00
by uc530
Hello!
I am new user of raspberry and domoticz and I am asking you for some help.
I have no success with the script to make it run. I made a file with name domoticz_state_checker.sh with:
Code: Select all
#!/bin/bash
while true
do
DomoticzState=`sudo service domoticz status`
if [ $DomoticzState == "active (running)" ]
then
echo 'Domoticz is running. Nothing to do.'
elif [ $DomoticzState == "inactive (dead)" ]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz restart
echo 'Domoticz restarted.'
fi
sleep 15
done
But I have all possible errors listed when I try to run it:
Code: Select all
sudo su pi /home/pi/domoticz/scripts/domoticz_state_checker.sh
/home/pi/domoticz/scripts/domoticz_state_checker.sh: line 10: syntax error near unexpected token `elif'
'home/pi/domoticz/scripts/domoticz_state_checker.sh: line 10: `elif [ $DomoticzState == "inactive (dead)" ]
If I change elif with elseif, then I have:
Code: Select all
sudo su pi /home/pi/domoticz/scripts/domoticz_state_checker.sh
/home/pi/domoticz/scripts/domoticz_state_checker.sh: line 18: syntax error near unexpected token `done'
/home/pi/domoticz/scripts/domoticz_state_checker.sh: line 18: `done'
Can anyone please write it from the beginning, how to make this script to work properly. Where to put the files, how to write the code correctly...
I run raspbyan jessie on RPI ver.1.
Thanks in advance!
Ps:Sorry for my english.
Re: Script to restart Domoticz if it crashes
Posted: Tuesday 07 March 2017 23:58
by K3rryBlue
You ran a bit short on [ and ]
Please use this:
Code: Select all
#!/bin/bash
while true
do
DomoticzState=`sudo service domoticz status`
if [[ $DomoticzState == *"active (running)"* ]]
then
echo 'Domoticz is running. Nothing to do.'
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz restart
echo 'Domoticz restarted.'
fi
sleep 15
done
To check this every 15 seconds might be an overkill.......
Re: Script to restart Domoticz if it crashes
Posted: Wednesday 08 March 2017 0:50
by uc530
Hi!
Thanks for the answer.
I tryed that alredy with the code you posted few days ago, but i`ve got errors:
Code: Select all
pi@raspberrypi:~ $ sudo su pi /home/pi/domoticz/scripts/domoticz_state_checker.sh
/home/pi/domoticz/scripts/domoticz_state_checker.sh: line 7: syntax error in conditional expression
'home/pi/domoticz/scripts/domoticz_state_checker.sh: line 7: syntax error near `]]
/home/pi/domoticz/scripts/domoticz_state_checker.sh: line 7: `if [[ $DomoticzState == *"active (runn'ng)"* ]]
About the 15 seconds.... I`ll change that with longer period.
Re: Script to restart Domoticz if it crashes
Posted: Wednesday 08 March 2017 10:12
by K3rryBlue
I think you are creating your files in windows and copy them to the rPi.
- Please copy the code below to your script file. I use as example "domoticz_status_check.sh"
Code: Select all
#!/bin/bash
while true
do
DomoticzState=`sudo service domoticz.sh status`
if [[ $DomoticzState == *"active (running)"* ]]
then
echo 'Domoticz is running. Nothing to do.'
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz.sh restart
echo 'Domoticz restarted.'
fi
sleep 15
done
- Save the file and run the following commands via putty"
Code: Select all
sudo chmod 755 domoticz_status_check.sh
- Remove the horror from windows
Code: Select all
sed -i -e 's/\r$//' domoticz_status_check.sh
- Execute the script
The script should run now
Re: Script to restart Domoticz if it crashes
Posted: Thursday 09 March 2017 0:01
by uc530
Thank you very much! It works!
Another one thing please... Procedure how to make the script to run after rpi reboot.
Thanks again! I owe you a big beer!
Re: Script to restart Domoticz if it crashes
Posted: Thursday 09 March 2017 0:12
by K3rryBlue
Re: Script to restart Domoticz if it crashes
Posted: Thursday 09 March 2017 18:02
by uc530
Hi!
Script without loop and crontab command works like charm.
Thanks again for help.
script and added all rights:
Code: Select all
#!/bin/bash
DomoticzState=`sudo service domoticz.sh status`
if [[ $DomoticzState == *"active (running)"* ]]
then
echo 'Domoticz is running. Nothing to do.'
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz.sh restart
echo 'Domoticz restarted.'
fi
crontab edit:
Code: Select all
crontab -e
*/1 * * * * /home/pi/domoticz/scripts/domoticz_state_checker.sh
With best regards UC530
Re: Script to restart Domoticz if it crashes
Posted: Friday 10 March 2017 0:04
by K3rryBlue
Thanks for your feedback. To make it even more complete you could add a simple log to your script, so you know when something happened.
If Domoticz need to restart it will write a datetime stamp to a file.
Code: Select all
#!/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
Re: Script to restart Domoticz if it crashes
Posted: Friday 10 March 2017 7:27
by jannl
I get a pushover notification when domoticz is restarted. I only check is json is respondig. With the status check you propably won't detect if domoticz hangs.
Re: Script to restart Domoticz if it crashes
Posted: Friday 10 March 2017 8:46
by havnegata
jannl wrote:I get a pushover notification when domoticz is restarted. I only check is json is respondig. With the status check you propably won't detect if domoticz hangs.
This is what I would like as well

Do you care to describe a bit closer how you achieve this?