source: trunk/init/samhain.startLinux.in@ 490

Last change on this file since 490 was 481, checked in by katerina, 9 years ago

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File size: 5.5 KB
RevLine 
[1]1#!/bin/bash
[481]2
[1]3# chkconfig: 2345 99 10
4# description: File Integrity Checking Daemon
5#
6# processname: @install_name@
7# config : @myconffile@
8# logfile : @mylogfile@
9# database: @mydatafile@
10#
11
[481]12### BEGIN INIT INFO
13# Provides: @install_name@
14# Required-Start: $syslog $network
15# Required-Stop: $syslog $network
16# Default-Start: 2 3 4 5
17# Default-Stop: 0 1 6
18# Short-Description: Keep an eye on stuff
19# Description: Keep an eye on stuff
20### END INIT INFO
21
[1]22# For Debian
23#
24FLAGS="defaults 99 10"
25
26NAME=@install_name@
27DAEMON=@sbindir@/@install_name@
28RETVAL=0
29VERBOSE=yes
30PIDFILE=@mylockfile@
31
32if [ -x $DAEMON ]; then
33 :
34else
35 echo "${0}: executable ${DAEMON} not found"
36 exit 0
37fi
38
39# Sort out sourcing in the distribution specific library functions
40# and the command to run them.
41if [ -f /etc/redhat-release ]; then
42 . /etc/init.d/functions
43 DISTRO=redhat
44elif [ -f /etc/mandrake-release ]; then
45 . /etc/init.d/functions
46 DISTRO=redhat
47elif [ -f /etc/yellowdog-release ]; then
48 . /etc/init.d/functions
49 DISTRO=redhat
50elif [ -f /etc/SuSE-release ]; then
51 . /etc/rc.config
52 . /etc/rc.status
53 # Determine the base and follow a runlevel link name.
54 base=${0##*/}
55 link=${base#*[SK][0-9][0-9]}
56 # Force execution if not called by a runlevel directory.
57 test $link = $base && START_@INSTALL_NAME@=yes
58 # Check whether START_@INSTALL_NAME@ is in /etc/rc.config
59 # If yes, abort unless its value is 'yes'
60 if test "x${START_@INSTALL_NAME@}" != "x"; then
61 test "${START_@INSTALL_NAME@}" = yes || exit 0
62 fi
63 return=$rc_done
64 DISTRO=suse
65elif [ -f /etc/debian_version ]; then
66 # . /etc/default/rcS
67 set -e
68 DISTRO=debian
69elif [ -f /etc/slackware-version ]; then
70 # . /etc/rc.d/rc.sysvinit
71 DISTRO=generic
72else
73 DISTRO=generic
74fi
75
[59]76debian_end()
[1]77{
78 if [ $RETVAL -eq 0 ];
79 then
80 echo "."
81 else
82 echo " failed."
83 fi
84}
85
86# Generic function "a la Red Hat"
87MOVE_TO_COL="echo -en \\033[60G"
88SETCOLOR_SUCCESS="echo -en \\033[1;32m"
89SETCOLOR_FAILURE="echo -en \\033[1;31m"
90SETCOLOR_NORMAL="echo -en \\033[0;39m"
91
92echo_success() {
93 $MOVE_TO_COL
94 echo -n "[ "
95 $SETCOLOR_SUCCESS
96 echo -n "OK"
97 $SETCOLOR_NORMAL
98 echo -n " ]"
99 echo -ne "\r"
100 echo ""
101}
102
103echo_failure() {
104 $MOVE_TO_COL
105 echo -n "["
106 $SETCOLOR_FAILURE
107 echo -n "FAILED"
108 $SETCOLOR_NORMAL
109 echo -n "]"
110 echo -ne "\r"
111 echo ""
112}
113
114
115# echo OK in green if is success, FAILED in red is failed
[59]116generic_end()
[1]117{
118 if [ $RETVAL -eq 0 ];
119 then
120 echo_success
121 else
122 echo_failure
123 fi
124}
125
126log_stat_msg () {
127case "$1" in
128 0)
129 echo "Service $NAME: Running";
130 ;;
131 1)
132 echo "Service $NAME: Stopped and /var/run pid file exists";
133 ;;
134 3)
135 echo "Service $NAME: Stopped";
136 ;;
137 *)
138 echo "Service $NAME: Status unknown";
139 ;;
140esac
141}
142
143
144case "$1" in
145 start)
146 #
147 # Remove a stale PID file, if found
148 #
149 if test -f ${PIDFILE}; then
150 /bin/rm -f ${PIDFILE}
151 fi
152 #
153 case "$DISTRO" in
154 debian)
155 echo -n "Starting ${NAME}"
[481]156 ( /sbin/start-stop-daemon --start --oknodo --quiet --exec $DAEMON )
[1]157 RETVAL=$?
158 debian_end
159 ;;
160 redhat)
[466]161 if [ -f /etc/sysconfig/${NAME} ]; then
162 . /etc/sysconfig/${NAME}
163 fi
[1]164 echo -n $"Starting ${NAME}: "
[466]165 if [ -n "$OPTIONS" ]; then
166 daemon $DAEMON $OPTIONS
167 else
168 daemon $DAEMON
169 fi
[1]170 RETVAL=$?
171 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/${NAME}
172 echo
173 ;;
174 suse)
175 echo -n "Starting service ${NAME}"
176 /sbin/startproc $DAEMON
177 RETVAL=$?
178 if [ $RETVAL -eq 0 ]; then
179 return=$rc_done
180 else
181 return=$rc_failed
182 fi
183 echo -e "$return"
184 ;;
185 *)
186 echo -n "Starting ${NAME} ... "
187 $DAEMON start
188 RETVAL=$?
189 generic_end
190 ;;
191 esac
192 exit $RETVAL
193 ;;
194
195 stop)
196 case "$DISTRO" in
197 debian)
198 echo -n "Stopping $NAME"
[481]199 ( /sbin/start-stop-daemon --stop --oknodo --quiet --exec $DAEMON )
[1]200 RETVAL=$?
201 debian_end
202 ;;
203 redhat)
204 echo -n $"Stopping ${NAME}: "
205 killproc ${NAME}
206 RETVAL=$?
207 rm -f /var/lock/subsys/${NAME}
208 echo
209 ;;
210 suse)
211 echo -n "Shutting down service ${NAME}"
212 /sbin/killproc -TERM $DAEMON
213 RETVAL=$?
214 if [ $RETVAL -eq 0 ]; then
215 return=$rc_done
216 else
217 return=$rc_failed
218 fi
219 echo -e "$return"
220 ;;
221 *)
222 if test x"$VERBOSE" != xno; then
223 echo -n "Stopping ${NAME} ... "
224 fi
225 $DAEMON stop
226 RETVAL=$?
227 generic_end
228 ;;
229 esac
230 #
231 # Remove a stale PID file, if found
232 #
233 if test -f ${PIDFILE}; then
234 /bin/rm -f ${PIDFILE}
235 fi
236 if test -S @mylockdir@/${NAME}.sock; then
237 /bin/rm -f @mylockdir@/${NAME}.sock
238 fi
239 ;;
240
241 restart)
242 $0 stop
243 sleep 3
244 $0 start
245 RETVAL=$?
246 ;;
247
248 reload|force-reload)
249 case "$DISTRO" in
250 debian)
251 echo -n "Reloading $NAME configuration files"
252 ( /sbin/start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON )
253 RETVAL=$?
254 debian_end
255 ;;
256 redhat)
257 echo -n $"Reloading ${NAME} configuration: "
258 killproc ${NAME} -HUP
259 RETVAL=$?
260 echo
261 ;;
262 suse)
263 echo -n "Reload service ${NAME}"
264 /sbin/killproc -HUP $DAEMON
265 RETVAL=$?
266 if [ $RETVAL -eq 0 ]; then
267 return=$rc_done
268 else
269 return=$rc_failed
270 fi
271 echo -e "$return"
272 ;;
273 *)
274 echo -n "Reloading ${NAME} ... "
275 $DAEMON reload
276 RETVAL=$?
277 generic_end
278 ;;
279 esac
280 ;;
281
282 status)
283 case "$DISTRO" in
284 redhat)
285 status ${NAME}
286 exit $?
287 ;;
288 suse)
289 echo -n "Checking for service ${NAME}: "
290 /sbin/checkproc $DAEMON
291 RETVAL=$?
292 if [ $RETVAL -eq 0 ]; then
293 return="OK"
294 else
295 return="No process"
296 fi
297 echo "$return"
298 exit $RETVAL
299 ;;
300 *)
301 $DAEMON status
302 ERRNUM=$?
303 log_stat_msg ${ERRNUM}
304 exit ${ERRNUM}
305 ;;
306 esac
307 ;;
308
309 *)
310 echo "$0 usage: {start|stop|status|restart|reload}"
311 exit 1
312 ;;
313esac
314
315exit $RETVAL
Note: See TracBrowser for help on using the repository browser.