This repository has been archived by the owner on Dec 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
domoticz.sh
121 lines (108 loc) · 2.38 KB
/
domoticz.sh
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/bash
#
# domoticz.sh init script for domoticz
#
# Modified for Debian GNU/Linux
### BEGIN INIT INFO
# Provides: domoticz
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Home Automation System
# Description: This daemon will start the Domoticz Home Automation System
### END INIT INFO
set -e
if [ -r "/lib/lsb/init-functions" ]; then
. /lib/lsb/init-functions
else
echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
exit 1
fi
LANG=C
export LANG
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DAEMON=/home/pi/domoticz/domoticz
NAME=domoticz
DESC="Domoticz Home Automation System"
PIDFILE=/var/run/$NAME.pid
[ "$LOGFILE" = "" ] && LOGFILE="/dev/null"
test -f $DAEMON || exit 0
# Defaults
OPTIONS="-www 8080"
# this is from madduck on IRC, 2006-07-06
# There should be a better possibility to give daemon error messages
# and/or to log things
log()
{
case "$1" in
[[:digit:]]*) success=$1; shift;;
*) :;;
esac
log_action_begin_msg "$1"; shift
log_action_end_msg ${success:-0} "$*"
}
start () {
if ! pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
log_daemon_msg "Starting $DESC"
# since we dont have a proper daemon, lets pretend...
$DAEMON $OPTIONS &> $LOGFILE &
pid=$!
if [ $! != 0 ]; then
echo $pid > $PIDFILE
log_end_msg 0
exit 1
else
log_end_msg 1
fi
ret=$?
else
log_failure_msg "already running!"
log_end_msg 1
exit 1
fi
return $ret
}
stop () {
# this is a workaround as Domoticz does not delete its pidfile
SIG="${1:--TERM}"
killproc -p "$PIDFILE" "$DAEMON" "$SIG"
# this is a workaround for killproc -TERM not zapping the pidfile
if ! pidofproc -p "$PIDFILE" "$DAEMON">/dev/null; then
rm -f $PIDFILE
fi
}
case "$1" in
start)
start
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC"
stop
log_end_msg 0
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC"
stop "-HUP"
log_end_msg 0
;;
restart)
log_daemon_msg "Restarting $DESC"
stop
sleep 8
start
log_end_msg 0
;;
status)
status_of_proc $DAEMON $NAME
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0