source: branches/samhain_3_1/init/samhain.startLinux.in@ 508

Last change on this file since 508 was 466, checked in by katerina, 10 years ago

Fix for ticket #366 (redhat init script).

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