Config: Raspberry Pi 3 with Raspbian Jessie.
I start Domoticz with systemd. File is /etc/systemd/system/domoticz.service :
Code: Select all
[Unit]
Description=Domoticz home automation
After=network.target
[Service]
ExecStartPre=/usr/local/bin/set-domoticz start
ExecStart=/opt/domoticz/domoticz -www 81 -sslwww 0 -dbase /tmp/domoticz.db
ExecStopPost=/usr/local/bin/set-domoticz stop
Restart=always
[Install]
WantedBy=multi-user.target
Code: Select all
#! /bin/bash
# path to adapt
domoticzdir="/opt/domoticz" # where lives Domoticz
db="/tmp/domoticz.db" # BD path in a tmpfs filesystem
ozwlog="/tmp/OZW_Log.txt" # OpenZwave log path in a tmpfs filesystem
heartbeat="/tmp/domoticz.heartbeat" # heartbeat file for watchdog
########################################################################
bckbase="$domoticzdir/backups/hourly/backup-hour-"
checkdb() {
if [ "$(sqlite3 -batch -bail -cmd 'pragma integrity_check;' -cmd '.quit' $1 2> /dev/null)" == ok ]; then
rm -f $1-shm $1-wal
return 0
fi
return 1
}
case "$1" in
start)
touch $heartbeat
rm -f $domoticzdir/Config/OZW_Log.txt
ln -s $ozwlog $domoticzdir/Config/
[ -e $db -a checkdb $b ] && exit 0 # DB exists and is OK
# looking for a working DB, newer first
for f in $(ls -t $bckbase*.db); do
if checkdb $f; then
cp -a $f $db
exit 0
fi
done
;;
stop)
# save DB if it is OK
[ -f $db ] && checkdb $db && cp -a $db $bckbase$(date "+%H").db || exit 1
;;
esac
exit 0
File heartbeat is for watchdog. For watchdog to monitor Domoticz, put in an lua script _time_XXX.lua :
Code: Select all
-- pour le watchdog
file = io.open("/tmp/domoticz.heartbeat", "w")
file:close()
Code: Select all
file = /tmp/domoticz.heartbeat
change = 300
Code: Select all
# BdA added for the watchdog
lbf="/root/lastboot"
actuel=$(date +%s)
if [ -f "$lbf" ]; then
last=$(cat "$lbf")
if (( actuel - last < 120 )); then
systemctl stop watchdog
fi
fi
echo $actuel > "$lbf"
date | mailx -s "Raspberry $(hostname) boot" [email protected]