]> git.sven.stormbind.net Git - sven/mpt-status.git/blobdiff - mpt-status.init
changelog spacing fix
[sven/mpt-status.git] / mpt-status.init
index 922442c11d510d8c389454ac6a644d2e49e2d37c..6599f3c52096bdc1c1c2c41b3605dad3dc27a72e 100644 (file)
@@ -1,14 +1,20 @@
 #! /bin/sh
 
 # Author: Petter Reinholdtsen <pere@hungry.com>
+# Author: Sven Hoexter <sven@timegate.de>
 # License: GNU General Public License v2 or later
+
+# mpt-statusd - Check mpt-status values in the background.
 #
+# chkconfig: - 60 50
+# description: Check mpt-status values in the background \
+# using daemonize and the mpt-status utility.
+
 ### BEGIN INIT INFO
-# Provides:          mpt-statusd
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
+# Provides: mpt-statusd
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Stop: 0 1 6
 # Short-Description: Check mpt-status values in the background.
 ### END INIT INFO
 
@@ -18,7 +24,7 @@ NAME=mpt-statusd
 PIDFILE=/var/run/$NAME.pid
 STATUSFILE=/var/run/$NAME.status
 SCRIPTNAME=/etc/init.d/$NAME
-
+LOCKFILE=/var/lock/subsys/$NAME
 
 # Do not touch you can configure this in /etc/default/mpt-statusd
 MAILTO=root   # Where to report problems
@@ -32,18 +38,20 @@ ID=0
 # Gracefully exit if the package has been removed.
 test -x /usr/sbin/mpt-status || exit 0
 
-. /lib/lsb/init-functions
-[ -e /etc/default/rcS ] && . /etc/default/rcS
+# Source function library.
+. /etc/rc.d/init.d/functions
 
 if [ $RUN_DAEMON = "no" ] ; then
-       log_begin_msg "mpt-statusd is disabled in /etc/default/mpt-statusd, not starting."
-       log_end_msg 0
+        echo "mpt-statusd is disabled in /etc/default/mpt-statusd, not starting." && failure
        exit 0
 fi
 
+
+#Try to blindly load the mptctl module
+modprobe mptctl || true
+
 if ! [ -e "/proc/mpt/version" ] ; then
-       log_failure_msg "The mptctl module is missing. Please have a look at the README.Debian.gz."
-       log_end_msg 0
+       echo "The mptctl module is missing." && failure
        exit 0
 fi
 
@@ -127,15 +135,16 @@ check_daemon() {
 d_start() {
     [ -f $PIDFILE ] && PID="`cat $PIDFILE`"
     if [ "$PID" ] ; then
-        log_progress_msg "Daemon already running. Refusing to start another"
+        echo "Daemon already running. Refusing to start another" && warning
         return 0
     elif check_daemon ; then
-        # Use the daemon package to turn this script into a daemon
-        start-stop-daemon --start --quiet --pidfile $PIDFILE \
-                --oknodo --exec /usr/bin/daemon /usr/bin/daemon $SCRIPTNAME check_mpt
-       return 0
+       # Use daemonize to turn it into a daemon and start it with daemon().
+        daemon --pidfile $PIDFILE /usr/sbin/daemonize $SCRIPTNAME check_mpt
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch $LOCKFILE
+       return $RETVAL
     else
-        log_progress_msg "Daemon is already running. Refusing to start another"
+        echo "Daemon is already running. Refusing to start another" && warning
         return 0
     fi
 }
@@ -145,10 +154,18 @@ d_start() {
 #
 d_stop() {
         if [ -f $PIDFILE ] ; then
-               start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE > /dev/null 2>&1 
-               rm -f $PIDFILE
+               killproc $SCRIPTNAME
+               RETVAL=$?
+               if [ $RETVAL -eq 0 ] ; then
+                   success "$NAME stopped"
+                   rm -f $PIDFILE $LOCKFILE
+                   return 0
+               else
+                   echo "$NAME failed to stop" && failure
+                   return 1
+               fi
         else
-                log_progress_msg "Daemon is already stopped."
+                echo "$NAME is already stopped." && warning
                 return 0
         fi
 }
@@ -157,39 +174,35 @@ d_stop() {
 # therefore can be used by a restart
 d_stop_by_restart() {
         if [ -f $PIDFILE ] ; then
-                start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE
-                rm -f $PIDFILE
-                log_end_msg 0
+                killproc -p $PIDFILE $SCRIPTNAME > /dev/null 2>&1
+                rm -f $PIDFILE $LOCKFILE
         else
-                log_progress_msg "Daemon is already stopped."
-                log_end_msg 0
+                echo "Daemon is already stopped." && warning
         fi
 }
 
 case "$1" in
   start)
-        echo -n ""
-        log_begin_msg "Starting $DESC: $NAME"
-        d_start ; CODE=$?
-        log_end_msg $CODE
+        echo $"Starting $DESC: $NAME"
+        d_start
+       echo
         ;;
   stop)
-        log_begin_msg "Stopping $DESC: $NAME"
-        d_stop ; CODE=$?
-        log_end_msg $CODE
+        echo $"Stopping $DESC: $NAME"
+        d_stop
+       echo
         ;;
   check_mpt)
         check_mpt
         ;;
   restart|force-reload)
-        log_begin_msg "Restarting $DESC: $NAME"
+        echo "Restarting $DESC: $NAME"
         d_stop_by_restart
         sleep 1
-        d_start || CODE=$?
-        log_end_msg $CODE
+        d_start
+       echo
         ;;
   *)
-        # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
         exit 1
         ;;