#!/bin/bash # # Init file for Domoticz Daemon [ -x /opt/domoticz/domoticz ] || exit 1 . /etc/default/domoticz RETVAL=0 prog="domoticz" STOPTIME=45 start() { echo -n "Starting Domoticz: " su - domoticz -c "/opt/domoticz/domoticz $DOMOTICZ_ARGS" >/dev/null 2>/dev/null echo "/opt/domoticz/domoticz" } stop() { echo -n "Stopping Domoticz: " if [ -f "$DOMOTICZ_PIDFILE" ]; then tim=0 su - domoticz -c "kill $(cat $DOMOTICZ_PIDFILE)" >/dev/null while [ true ]; do [ ! -f "$DOMOTICZ_PIDFILE" ] && break; [ $tim -gt $STOPTIME ] && break; echo -n "." sleep 1 tim=$(($tim+1)) done if [ -f "$DOMOTICZ_PIDFILE" ]; then su - domoticz -c "kill -9 $(cat $DOMOTICZ_PIDFILE)" >/dev/null echo -n "!" sleep 1 echo -n "!" rm -f $DOMOTICZ_PIDFILE fi fi echo "" } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) if [ ! -f "$DOMOTICZ_PIDFILE" ]; then echo "Status Domoticz: not running" else su - domoticz -c "kill -0 $(cat $DOMOTICZ_PIDFILE)" >/dev/null 2>/dev/null if [ "$?" == "0" ]; then echo "Status Domoticz: running with pid $(cat $DOMOTICZ_PIDFILE)" else echo "Status Domoticz: stale pidfile, removed." rm -f $DOMOTICZ_PIDFILE fi fi ;; *) echo "Usage: $0 {start|stop|restart|status}" esac