forked from SirWumpus/milter-spiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.sh.in
executable file
·184 lines (159 loc) · 2.78 KB
/
startup.sh.in
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
#
# @package_copyright@
#
# @configure_input@
#
# $OpenBSD$
# chkconfig: 345 87 12
# description: @PACKAGE_NAME@
# REQUIRE: syslogd
# BEFORE: mail
# KEYWORD: FreeBSD NetBSD
prefix="@prefix@"
exec_prefix="@exec_prefix@"
libexecdir="@libexecdir@"
sbindir="@sbindir@"
localstatedir="@localstatedir@"
PACKAGE_NAME="@PACKAGE_NAME@"
PID_FILE="@enable_pid@"
COLUMN='\r\033[71C'
FG_RED='\033[1;31m'
FG_GREEN='\033[1;32m'
FG_NORMAL='\033[0m'
##########################################################################
# Nothing to be configured below this point.
##########################################################################
if test -x $libexecdir/$PACKAGE_NAME ; then
PROGRAM=$libexecdir/$PACKAGE_NAME
elif test -x $sbindir/$PACKAGE_NAME ; then
PROGRAM=$sbindir/$PACKAGE_NAME
else
echo "$PACKAGE_NAME not found".
exit 0;
fi
os=`uname -s`
unalias announce >/dev/null 2>&1
announce()
{
case $os in
Linux*)
printf "$1"
;;
esac
}
unalias pass >/dev/null 2>&1
pass()
{
case $os in
Linux*)
printf ${COLUMN}'['${FG_GREEN}' OK '${FG_NORMAL}']\n'
;;
*)
echo -n " $PACKAGE_NAME"
;;
esac
}
unalias fail >/dev/null 2>&1
fail()
{
case $os in
Linux*)
printf ${COLUMN}'['${FG_RED}'FAILED'${FG_NORMAL}']\n'
;;
*)
;;
esac
}
#
# I choose to use getpid() instead of the $PID_FILE, because .pid
# files can disappear while the program is still running.
#
unalias getpid >/dev/null 2>&1
getpid()
{
sleep 1
case $os in
Linux*)
ps acxj | grep "$PACKAGE_NAME" | sed -n -e '/^ *1 /{
s/^ *[^ ][^ ]* *\([0-9][0-9]*\).*/\1/
p
}'
;;
SunOS)
ps -ef | grep "$PACKAGE_NAME" | sed -n -e '/^ *[^ ][^ ]* *[0-9][0-9]* *1 /{
s/^ *[^ ][^ ]* *\([0-9][0-9]*\).*/\1/
p
}'
;;
*BSD*)
ps -acxj | grep "$PACKAGE_NAME" | sed -n -e '/^ *[^ ][^ ]* *[0-9][0-9]* *1 /{
s/^ *[^ ][^ ]* *\([0-9][0-9]*\).*/\1/
p
}'
;;
esac
}
unalias start >/dev/null 2>&1
start()
{
announce "Starting $PACKAGE_NAME"
pid=`getpid "$PROGRAM"`
if test X"$pid" != X ; then
# I'm not dead yet.
fail
return
fi
$PROGRAM $OPTIONS
pid=`getpid "$PROGRAM"`
if test X"$pid" = X ; then
# I think I'm dead.
fail
return
fi
pass
}
unalias stop >/dev/null 2>&1
stop()
{
announce "Stopping $PACKAGE_NAME"
# The milter knows how to terminate a running instance of itself.
$PROGRAM -x
sleep 1
pid=`getpid "$PROGRAM"`
if test X"$pid" != X ; then
# I'm not dead yet.
kill -KILL $pid
pid=`getpid "$PROGRAM"`
if test X"$pid" != X ; then
# I'm still not dead.
fail
return
fi
fi
pass
}
case "$1" in
restart)
stop
start
;;
start)
start
;;
stop)
stop
;;
status)
pid=`getpid "$PROGRAM"`
if test X"$pid" != X ; then
echo "$PACKAGE_NAME:${pid}"
else
echo "$PACKAGE_NAME:STOPPED"
fi
;;
*)
echo "Usage: $PACKAGE_NAME {start|stop|restart|status}"
exit 1
esac
exit $?