-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sc.func
129 lines (117 loc) · 3.32 KB
/
sc.func
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
#!/bin/sh
## THIS FILE IS A COPY OF ENTWARE'S /opt/etc/init.d/rc.func ##
########## Shellcheck directives ###########
# shellcheck disable=SC2034
# shellcheck disable=SC2039
# shellcheck disable=SC2153
# shellcheck disable=SC2166
######################################################
ACTION=$1
CALLER=$2
ansi_red="\033[1;31m";
ansi_white="\033[1;37m";
ansi_green="\033[1;32m";
ansi_yellow="\033[1;33m";
ansi_blue="\033[1;34m";
ansi_bell="\007";
ansi_blink="\033[5m";
ansi_std="\033[m";
ansi_rev="\033[7m";
ansi_ul="\033[4m";
start() {
CHECKPROC="$(echo $PROC | awk 'FS="/" {print $NF;}')"
[ "$CRITICAL" != "yes" -a "$CALLER" = "cron" ] && return 7
[ "$ENABLED" != "yes" ] && return 8
echo -e -n "$ansi_white Starting $DESC... $ansi_std"
if [ -n "`pidof $CHECKPROC`" ]; then
echo -e " $ansi_yellow already running. $ansi_std"
return 0
fi
$PRECMD > /dev/null 2>&1
$PREARGS $PROC $ARGS > /dev/null 2>&1 &
#echo $PREARGS $PROC $ARGS
COUNTER=0
LIMIT=10
while [ -z "`pidof $CHECKPROC`" -a "$COUNTER" -le "$LIMIT" ]; do
sleep 1;
COUNTER=`expr $COUNTER + 1`
done
$POSTCMD > /dev/null 2>&1
if [ -z "`pidof $CHECKPROC`" ]; then
echo -e " $ansi_red failed. $ansi_std"
logger "Failed to start $DESC from $CALLER."
return 255
else
echo -e " $ansi_green done. $ansi_std"
logger "Started $DESC from $CALLER."
return 0
fi
}
stop() {
CHECKPROC="$(echo $PROC | awk 'FS="/" {print $NF;}')"
case "$ACTION" in
stop | restart)
echo -e -n "$ansi_white Shutting down $CHECKPROC... $ansi_std"
killall $PROC 2>/dev/null
COUNTER=0
LIMIT=10
while [ -n "`pidof $CHECKPROC`" -a "$COUNTER" -le "$LIMIT" ]; do
sleep 1;
COUNTER=`expr $COUNTER + 1`
done
;;
kill)
echo -e -n "$ansi_white Killing $CHECKPROC... $ansi_std"
killall -9 $CHECKPROC 2>/dev/null
;;
esac
if [ -n "`pidof $CHECKPROC`" ]; then
echo -e " $ansi_red failed. $ansi_std"
return 255
else
echo -e " $ansi_green done. $ansi_std"
return 0
fi
}
check() {
CHECKPROC="$(echo $PROC | awk 'FS="/" {print $NF;}')"
echo -e -n "$ansi_white Checking $DESC... "
if [ -n "`pidof $CHECKPROC`" ]; then
echo -e " $ansi_green alive. $ansi_std";
return 0
else
echo -e " $ansi_red dead. $ansi_std";
return 1
fi
}
reconfigure() {
CHECKPROC="$(echo $PROC | awk 'FS="/" {print $NF;}')"
SIGNAL=SIGHUP
echo -e "$ansi_white Sending $SIGNAL to $CHECKPROC... $ansi_std"
killall -$SIGNAL $CHECKPROC 2>/dev/null
}
for PROC in $PROCS; do
case $ACTION in
start)
start
;;
stop | kill )
check && stop
;;
restart)
check > /dev/null && stop
start
;;
check)
check
;;
reconfigure)
reconfigure
;;
*)
echo -e "$ansi_white Usage: $0 (start|stop|restart|check|kill|reconfigure)$ansi_std"
exit 1
;;
esac
done
#logger "Leaving ${0##*/}."