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

Last change on this file since 446 was 321, checked in by katerina, 14 years ago

Fix for ticket #240: The samhain_kmem kernel module should be loaded earlier

File size: 5.1 KB
Line 
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
65debian_end()
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
105generic_end()
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 # Preloaded kernel module
143 #
144 @sh_insmod_pre@
145 #
146 case "$DISTRO" in
147 debian)
148 echo -n "Starting ${NAME}"
149 ( /sbin/start-stop-daemon --start --quiet --exec $DAEMON )
150 RETVAL=$?
151 debian_end
152 ;;
153 redhat)
154 echo -n $"Starting ${NAME}: "
155 daemon $DAEMON
156 RETVAL=$?
157 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/${NAME}
158 echo
159 ;;
160 suse)
161 echo -n "Starting service ${NAME}"
162 /sbin/startproc $DAEMON
163 RETVAL=$?
164 if [ $RETVAL -eq 0 ]; then
165 return=$rc_done
166 else
167 return=$rc_failed
168 fi
169 echo -e "$return"
170 ;;
171 *)
172 echo -n "Starting ${NAME} ... "
173 $DAEMON start
174 RETVAL=$?
175 generic_end
176 ;;
177 esac
178 #
179 # The hiding kernel module
180 #
181 if [ $RETVAL -eq 0 ]; then
182 @sh_insmod_cmd@
183 fi
184 exit $RETVAL
185 ;;
186
187 stop)
188 case "$DISTRO" in
189 debian)
190 echo -n "Stopping $NAME"
191 ( /sbin/start-stop-daemon --stop --quiet --exec $DAEMON )
192 RETVAL=$?
193 debian_end
194 ;;
195 redhat)
196 echo -n $"Stopping ${NAME}: "
197 killproc ${NAME}
198 RETVAL=$?
199 rm -f /var/lock/subsys/${NAME}
200 echo
201 ;;
202 suse)
203 echo -n "Shutting down service ${NAME}"
204 /sbin/killproc -TERM $DAEMON
205 RETVAL=$?
206 if [ $RETVAL -eq 0 ]; then
207 return=$rc_done
208 else
209 return=$rc_failed
210 fi
211 echo -e "$return"
212 ;;
213 *)
214 if test x"$VERBOSE" != xno; then
215 echo -n "Stopping ${NAME} ... "
216 fi
217 $DAEMON stop
218 RETVAL=$?
219 generic_end
220 ;;
221 esac
222 #
223 # Remove a stale PID file, if found
224 #
225 if test -f ${PIDFILE}; then
226 /bin/rm -f ${PIDFILE}
227 fi
228 if test -S @mylockdir@/${NAME}.sock; then
229 /bin/rm -f @mylockdir@/${NAME}.sock
230 fi
231 ;;
232
233 restart)
234 $0 stop
235 sleep 3
236 $0 start
237 RETVAL=$?
238 ;;
239
240 reload|force-reload)
241 case "$DISTRO" in
242 debian)
243 echo -n "Reloading $NAME configuration files"
244 ( /sbin/start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON )
245 RETVAL=$?
246 debian_end
247 ;;
248 redhat)
249 echo -n $"Reloading ${NAME} configuration: "
250 killproc ${NAME} -HUP
251 RETVAL=$?
252 echo
253 ;;
254 suse)
255 echo -n "Reload service ${NAME}"
256 /sbin/killproc -HUP $DAEMON
257 RETVAL=$?
258 if [ $RETVAL -eq 0 ]; then
259 return=$rc_done
260 else
261 return=$rc_failed
262 fi
263 echo -e "$return"
264 ;;
265 *)
266 echo -n "Reloading ${NAME} ... "
267 $DAEMON reload
268 RETVAL=$?
269 generic_end
270 ;;
271 esac
272 ;;
273
274 status)
275 case "$DISTRO" in
276 redhat)
277 status ${NAME}
278 exit $?
279 ;;
280 suse)
281 echo -n "Checking for service ${NAME}: "
282 /sbin/checkproc $DAEMON
283 RETVAL=$?
284 if [ $RETVAL -eq 0 ]; then
285 return="OK"
286 else
287 return="No process"
288 fi
289 echo "$return"
290 exit $RETVAL
291 ;;
292 *)
293 $DAEMON status
294 ERRNUM=$?
295 log_stat_msg ${ERRNUM}
296 exit ${ERRNUM}
297 ;;
298 esac
299 ;;
300
301 *)
302 echo "$0 usage: {start|stop|status|restart|reload}"
303 exit 1
304 ;;
305esac
306
307exit $RETVAL
Note: See TracBrowser for help on using the repository browser.