tag 736375 pending
thanks

On Wed, Jan 22, 2014 at 10:34:55PM +0100, Peter Palfrader wrote:
> the samhain in stable-updates has an init script that fails on "start"
> if the service is already running:

I have made improvements to the init.d script and uploaded a preliminary fix
for this bug into unstable.

The fix for this is attached and I will make an upload to stable-updates if
RM allows.

Regards

Javier
diff --git a/debian/changelog b/debian/changelog
index f54f8f9..5d8800e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+samhain (2.8.3a-1+deb7u2) stable; urgency=medium
+
+  * debian/samhain.init: Improve the init script
+      - Do not fail in 'start' if the daemon is already started, use --oknodo
+        (Closes: #736375)
+      - Do not try to stop the daemon (and wait for it to stop) if it is not
+        running
+      - If the pidfile has been lost, try to determine the status using the
+        process name instead
+
+ -- Javier Fernández-Sanguino Peña <j...@debian.org>  Thu, 23 Jan 2014 03:45:25 +0100
+
 samhain (2.8.3a-1+deb7u1) stable; urgency=medium
 
   * Backport fixes from unstable version to fix serious/important bugs 
diff --git a/debian/samhain.init b/debian/samhain.init
index 30cffab..c9e5828 100644
--- a/debian/samhain.init
+++ b/debian/samhain.init
@@ -30,14 +30,17 @@ set -e
 # Check if a daemon is running
 running()
 {
-    # No pidfile, probably no daemon present
-    #
-    [ ! -f "$PIDFILE" ] && return 1
-    pid=`cat $PIDFILE`
-    # No pid, probably no daemon present
-    [ -z "$pid" ] && return 1
-
-    pidofproc -p $PIDFILE
+# Check with pidfile first, if available
+    if [ -r "$PIDFILE" ] ; then
+	    pid=`cat $PIDFILE`
+# No pid, probably no daemon present
+	    if [ -n "$pid" ] ; then
+		    pidofproc -p $PIDFILE
+		    return $?
+	    fi
+    fi
+# Try to find the daemon by name
+    pidof $DAEMON >/dev/null 
     return $?
 }
 
@@ -46,7 +49,7 @@ case "$1" in
   start)
         [ ! -e /var/run/${NAME} ] && mkdir -p /var/run/${NAME}
         log_begin_msg "Starting $DESC: $NAME"
-        start-stop-daemon --start --quiet --exec $DAEMON
+        start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
         log_end_msg $?
         ;;
   stop)
@@ -55,27 +58,39 @@ case "$1" in
         log_end_msg $?
         ;;
   reload)
-        log_begin_msg "Reloading $DESC configuration files: $NAME"
-        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
-        log_end_msg $?
+  	log_begin_msg "Reloading $DESC configuration files: $NAME"
+	if running ; then
+		start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
+		log_end_msg $?
+	else
+            	log_daemon_msg " ERROR: $DAEMON is not running."
+		log_end_msg 1
+	fi
+
   	;;
   restart|force-reload)
         log_begin_msg "Restarting $DESC: $NAME"
-        start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE  --name  $NAME 
-        for i in 1 2 3 ; do
-            if ! running; then break ; fi
-            sleep 1
-        done
+	if running; then
+	        start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE  --name  $NAME 
+	        for i in 1 2 3 ; do
+	            if ! running; then break ; fi
+	            sleep 1
+	        done
+	fi
         if  ! running  ; then
-            start-stop-daemon --start --quiet --exec $DAEMON
+            start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
             log_end_msg $?
         else
-            log_daemon_msg " ERROR: $DAEMON did not die in the expected time, will not reload"
+            log_daemon_msg " ERROR: $DAEMON did not die in the expected time, will not restart/force-reload"
             log_end_msg 1
         fi
         ;;
    status)
-        status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
+	if [ -e $PIDFILE ] ; then
+	   	status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
+	else
+	   	status_of_proc $DAEMON $NAME && exit 0 || exit $?
+	fi
         ;;
   *)
         N=/etc/init.d/${0##*/}

Attachment: signature.asc
Description: Digital signature

Reply via email to