-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmotd_stat
executable file
·96 lines (87 loc) · 1.86 KB
/
motd_stat
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: motd_stat
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the MOTD statistics monitor
# Description: Starts motd_stat using start-stop-daemon
### END INIT INFO
NAME=motd_stat
DESC=motd_stat
PID_FILE=/var/run/$NAME.pid
DAEMON_HOME=/usr/local/motd_gen
DAEMON=$DAEMON_HOME/motd_stat.py
DAEMON_OPTS=""
# Pre-check
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
running() {
[ ! -f "$PID_FILE" ] && return 1
[ ! -d /proc/$(cat $PID_FILE) ] && return 1
return 0
}
start_server() {
echo "Starting $DESC:"
start-stop-daemon --start --quiet --pidfile $PID_FILE --make-pidfile --background --startas $DAEMON -- $DAEMON_OPTS && RET_CODE=0 || RET_CODE=$?
if [ $RET_CODE -eq 0 ]; then
sleep 0.5
if running; then
log_success_msg "$NAME started"
else
log_failure_msg "$NAME not started"
rm -f $PID_FILE
return 1
fi
elif [ $RET_CODE -eq 1 ]; then
log_warning_msg "$NAME already started"
else
log_failure_msg "$NAME not started"
fi
return $RET_CODE
}
stop_server() {
echo "Stopping $DESC:"
start-stop-daemon --stop --quiet --pidfile $PID_FILE && RET_CODE=0 || RET_CODE=$?
if [ $RET_CODE -eq 0 ]; then
log_success_msg "$NAME stopped"
elif [ $RET_CODE -eq 1 ]; then
log_warning_msg "$NAME already stopped"
else
log_failure_msg "$NAME not stopped"
fi
running || rm -f $PID_FILE
return $RET_CODE
}
status_server() {
echo "Checking $DESC status:"
if running; then
log_success_msg "$NAME is running"
else
log_warning_msg "$NAME is not running"
fi
return 0
}
case "$1" in
start)
start_server
;;
stop)
stop_server
;;
restart)
stop_server || true
sleep 0.5
start_server
;;
status)
status_server
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0