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