blob: f2f91fed3a880faedefc9002729db34437659751 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/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
|