here is my take on this for Raspberry pi and Ubntu/debian systems
I do not run on synology, sorry
all documented in the code
if you need positive confirmation, redirect the echo commands to /var/log/syslog
hope someone benefits.
Code: Select all
#!/bin/bash
#****************************************************************************
# program : check-domoticz-active.sh
# programmer : RM
# date : 2019-03-21
#
# install in cron with crontab -e to run every 5 minutes
#
# m h dom mon dow command
# */5 * * * * /home/pi/domoticz/scripts/check-domoticz-active.sh >/dev/null 2>&1
#
#
# prerequisites
# jq installed (apt-get install jq)
# make sure the cron entry (example above)has the full path to the script!!
#
# revision
# 0.0.1 2019-03-21 initial release
#
#
#****************************************************************************
i=0
while [ $i -lt 3 ]
do
# check if domoticz responds to a json query
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
echo "Domoticz responded"
break # all ok
else
i=$(( $i + 1 ))
echo "Domoticz did not respond on try $i "
fi
sleep 5
done
# if we do not have an OK, domoticz did not respond, stop and start it
if [ "$STATUS" != "OK" ] ; then
echo "Stopping domoticz"
sudo systemctl stop domoticz.service
sleep 10
echo "Starting domoticz"
NOW=$(date +"%Y-%m-%d %H:%M:%S")
sudo systemctl start domoticz.service
Exitcode=$? # save systemctl exit code
if [ $Exitcode != 0 ] ; then
echo "$NOW - sudo systemctl start domoticz.service failed with exit code $Exitcode"
else
echo "$NOW - sudo systemctl start domoticz.service completed with exit code $Exitcode"
fi
fi
# end of source