forked from empierre/MyDomoAtHome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyDomoAtHome.sh
134 lines (117 loc) · 2.21 KB
/
MyDomoAtHome.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
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
### BEGIN INIT INFO
# Provides: ImperiHomestart
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start imperihome
# Description: Imperihome.
### END INIT INFO
# Start a Plack daemon.
# CHANGE TO YOUR PATH HERE
APP_DIR="/home/pi/domoticz/"
PORT=3001
# DO NOT CHANGE BELOW
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$HOME/perl5/bin
DAEMON="/usr/bin/plackup"
NAME="MyDomoAtHome"
PIDFILE=/var/run/$NAME.pid
USER=www-data
GROUP=www-data
CWD=`pwd`
# Defaults
RUN="no"
OPTIONS="-E production -s Starman --workers=4 --user $USER --group $GROUP --port $PORT -a $APP_DIR/MyDomoAtHome/bin/app.pl"
#
# These compatibility funcs are here just for sarge backports.
# They will be removed post-etch.
#
log_daemon_msg() {
echo -n "$1: $2"
}
log_end_msg() {
if [ $1 -ne 0 ]; then
echo " failed!"
else
echo "."
fi
}
[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions
start()
{
log_daemon_msg "Starting plack server" "$NAME"
start-stop-daemon -b -m --start --quiet --pidfile "$PIDFILE" --exec $DAEMON -- $OPTIONS
if [ $? != 0 ]; then
log_end_msg 1
exit 1
else
log_end_msg 0
fi
}
signal()
{
if [ "$1" = "stop" ]; then
SIGNAL="TERM"
log_daemon_msg "Stopping plack server" "$NAME"
else
if [ "$1" = "reload" ]; then
SIGNAL="HUP"
log_daemon_msg "Reloading plack server" "$NAME"
else
echo "ERR: wrong parameter given to signal()"
exit 1
fi
fi
if [ -f "$PIDFILE" ]; then
start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
if [ $? = 0 ]; then
log_end_msg 0
else
SIGNAL="KILL"
start-stop-daemon --stop --signal $SIGNAL --quiet --pidfile "$PIDFILE"
if [ $? != 0 ]; then
log_end_msg 1
[ $2 != 0 ] || exit 0
else
rm "$PIDFILE"
log_end_msg 0
fi
fi
if [ "$SIGNAL" = "KILL" ]; then
rm -f "$PIDFILE"
fi
else
log_end_msg 0
fi
}
case "$1" in
start)
start
;;
force-start)
start
;;
stop)
signal stop 0
;;
force-stop)
signal stop 0
;;
reload)
signal reload 0
;;
force-reload|restart)
signal stop 1
sleep 2
start
;;
status)
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$NAME {start|force-start|stop|status|force-stop|reload|restart|force-reload}"
exit 1
;;
esac
exit 0