forked from drahamim/invenflask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.d_invenflask
executable file
·67 lines (62 loc) · 1.48 KB
/
init.d_invenflask
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: invenflask
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# X-Start-Before:
# X-Stop-After:
# Default-Start: 2 3 4
# Default-Stop: 0 6
# Short-Description: runs invenflask dev mode
### END INIT INFO
_stop ()
{
echo killall gunicorn
killall gunicorn
echo 'STOPPED (I hope)'
# bug: pid is of the su process. killing it doesn't stop forked off gunicorn processes
# if [ -f /var/run/invenflask.pid ] ; then
# echo kill $(cat /var/run/invenflask.pid)
# kill $(cat /var/run/invenflask.pid)
# rm -f /var/run/invenflask.pid
# echo 'STOPPED (I hope)'
# fi
}
_start ()
{
_stop # always stop because of above bug
for F in /home/invenflask/init.sh /home/kjw/github/invenflask/init.sh ; do
if [ -f "${F}" ] ; then
echo "${F}"
su -c "${F}" invenflask &
#echo $! >/var/run/invenflask.pid
echo 'STARTED'
break
fi
done
}
case "$1" in
start)
_start
;;
stop)
_stop
;;
restart)
_stop
_start
;;
install)
cat "$0" >/etc/init.d/invenflask
chmod +x /etc/init.d/invenflask
ln -sf ../init.d/invenflask /etc/rc2.d/S99invenflask
ln -sf ../init.d/invenflask /etc/rc3.d/S99invenflask
ln -sf ../init.d/invenflask /etc/rc4.d/S99invenflask
ln -sf ../init.d/invenflask /etc/rc6.d/K01invenflask
ln -sf ../init.d/invenflask /etc/rc0.d/K01invenflask
;;
*)
echo 'Usage: $0 [start|stop|restart|install]' >&2
exit 1
;;
esac