forked from mrkipling/maraschino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initd
executable file
·156 lines (122 loc) · 3.85 KB
/
initd
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /bin/sh
# Copyright (C) 2011- by Mar2zz <LaSi.Mar2zz@gmail.com>
# released under GPL, version 2 or later
################################################
# #
# TO CONFIGURE EDIT /etc/default/maraschino
# #
################################################
### BEGIN INIT INFO
# Provides: Maraschino application instance
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of Maraschino
# Description: starts instance of Maraschino using start-stop-daemon
### END INIT INFO
# main variables
DAEMON=/usr/bin/python
SETTINGS=/etc/default/maraschino
SETTINGS_LOADED=FALSE
DESC=Maraschino
# only accept values from /etc/default/maraschino
unset RUN_AS CONFIG DATADIR PID_FILE
. /lib/lsb/init-functions
[ -x $DAEMON ] || {
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
return 1; }
[ -r $SETTINGS ] || {
log_warning_msg "$DESC: Can't read settings, aborting. See $SETTINGS";
return 1; }
check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS
[ -n "$APP_PATH" ] || {
log_warning_msg "$DESC: path to $DESC not set, aborting. See $SETTINGS";
return 1; }
[ -n "$PORT" ] || {
log_warning_msg "$DESC: port not set, aborting. See $SETTINGS";
return 1; }
[ $ENABLE_DAEMON != 1 ] && {
log_warning_msg "$DESC: daemon not enabled, aborting. See $SETTINGS";
return 1; }
[ -z "$RUN_AS" ] && {
log_warning_msg "$DESC: daemon username not set, aborting. See $SETTINGS";
return 1; }
[ -z "${RUN_AS%:*}" ] && exit 1
DAEMON_OPTS="Maraschino.py --port=$PORT"
[ -n "$HOST" ] && DAEMON_OPTS="$DAEMON_OPTS --host=$HOST"
[ -n "$WEBROOT" ] && DAEMON_OPTS="$DAEMON_OPTS --webroot=$WEBROOT"
[ $KIOSK -eq 1 ] && DAEMON_OPTS="$DAEMON_OPTS --kiosk"
[ -n "$PID_FILE" ] && PID_FILE=$PID_FILE
[ -n "$PID_FILE" ] || PID_FILE=/var/run/maraschino/maraschino.pid
SETTINGS_LOADED=TRUE
fi
return 0
}
load_settings || exit 0
is_running () {
# returns 1 when running, else 0.
PID=$(pgrep -f "Maraschino.py --port=$PORT")
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
}
handle_pid () {
PID_PATH=`dirname $PID_FILE`
[ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
log_warning_msg "$DESC: Could not create $PID_FILE, aborting.";
return 1;}
}
enable_updates () {
chown -R $RUN_AS $APP_PATH > /dev/null || {
log_warning_msg "$DESC: $APP_PATH not writable for web-updates, See $SETTINGS";
return 0; }
}
start_maraschino () {
if ! is_running; then
log_daemon_msg "Starting $DESC"
[ "$WEB_UPDATE" = 1 ] && enable_updates
handle_pid
start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
check_retval
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}
stop_maraschino () {
if is_running; then
log_daemon_msg "Stopping $DESC"
start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15
check_retval
else
log_success_msg "$DESC: not running"
fi
}
case "$1" in
start)
start_maraschino
;;
stop)
stop_maraschino
;;
restart|force-reload)
stop_maraschino
start_maraschino
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0