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

Last change on this file since 120 was 59, checked in by rainer, 18 years ago

Fix for exit status if database load fails; fix for problem with GrowingLogFiles if signed database is used; better support for *BSD init script installation.

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