#!/bin/sh # # domoticz This shell script takes care of starting and stopping # domoticz, the home automation system. # [ ! -x /opt/domoticz/domoticz ] && exit 99 [ ! -f /etc/default/domoticz ] && exit 99 # Source the configuration file: source /etc/default/domoticz DOMO_DAEMON="/opt/domoticz/domoticz" DOMO_PIDFILE="/var/run/domoticz/domoticz.pid" domoticz_start() { if [ -e "$PIDFILE" ]; then echo -n "Domoticz daemon (domoticz) already started!" else echo -n "Starting domoticz: " su - domoticz -s /bin/bash -c "$DOMO_DAEMON $DOMO_OPTS -pidfile $DOMO_PIDFILE" echo "- done." fi } domoticz_stop() { echo -n "Shutting down domoticz: " if [ -f $DOMO_PIDFILE ]; then # First try to stop processes gracefully: su - domoticz -s /bin/bash -c "kill $(cat $DOMO_PIDFILE)" RETVAL="$?" # Sub-processes may take more time to stop. for SEQ in $(seq 1 10); do [ ! -f $DOMO_PIDFILE ] && break; echo -n "." sleep 1 done if [ -f "$DOMO_PIDFILE" ]; then # Force-kill eventually: su - domoticz -s /bin/bash -c "kill -9 $(cat $DOMO_PIDFILE)" RETVAL="$?" echo -n "killed!" sleep 1 rm -f $DOMO_PIDFILE fi fi echo return $RETVAL } domoticz_reload() { if [ -f $DOMO_PIDFILE ]; then echo -n "Reloading domoticz: " kill -HUP $(cat $DOMO_PIDFILE) echo "- done." return $? else return 99 fi } domoticz_restart() { domoticz_stop sleep 2 domoticz_start } domoticz_status() { if [ -f $DOMO_PIDFILE ]; then echo "domoticz is running." ps up $(cat $DOMO_PIDFILE) return 0 else echo "domoticz is not running." return 1 fi } case "$1" in start) domoticz_start ;; stop) domoticz_stop ;; reload) domoticz_reload ;; restart) domoticz_restart ;; status) domoticz_status ;; *) echo "Usage: $0 start|stop|reload|restart|status" exit 1 ;; esac exit 0