Thought I share a (very basic) script that I use to check if Domoticz has crashed (offline) and restart it, I have this setup on a cron job running every ten minutes.
My script basically launches a Telnet session to Domoticz on port 8080, if it fails to connect it removes the 2 temporary DB files -shm and -wal and relaunches the service.
This code could probably be written in one line by one of you geniuses, but as I'm not a coder - it works for me!
Hope that helps someone else who has frequent offline crashes...
---
Code: Select all
#!/bin/bash
# This is a script to check if Domoticz is running or crashed, if crashed delete the 2 db files and relaunch - my script lives in a folder called domo-alive-test
(
echo open 127.0.0.1 8080
sleep 2
echo "exit"
) | telnet > /home/pi/domo-alive-test/info-output.txt
sleep 5
# Telnet connection check, lets open info-out and make sure it contains the failed telnet output otherwise stop.
grep -Po '\?Invalid command' /home/pi/domo-alive-test/info-output.txt > /home/pi/domo-alive-test/telnet-connection-test.txt
sed -i '1!d' /home/pi/domo-alive-test/telnet-connection-test.txt
info=$(cat /home/pi/domo-alive-test/telnet-connection-test.txt)
rm /home/pi/domo-alive-test/telnet-connection-test.txt
if [ "$info" = "?Invalid command" ]
then
# Telnet connection refused
rm /home/pi/domo-alive-test/info-output.txt
rm /home/pi/domoticz/domoticz.db-wal
rm /home/pi/domoticz/domoticz.db-shm
sudo service domoticz.sh start
exit
else
exit
fi