Package: fetchmail
Version: 6.3.9~rc2-4+b1
Severity: wishlist
Tags: patch
User: [email protected]
Usertags: initd-status-support

Here is an attempted patch to support the "status" action in the init.d 
script.  It's a bit messy, since it tries to achive that "status" can run 
usefully even as non-root and when the service is not configured.  You may 
want to refactor the init script somehow and choose a different solution.  Let 
me know if you need input.

Notes on the patch:

@@ -31,16 +31,12 @@
 PIDFILE="/var/run/fetchmail/fetchmail.pid"
 UIDL="/var/lib/fetchmail/.fetchmail-UIDL-cache"

-if [ ! -e $CONFFILE ]; then
-    exit 0
-fi
-
 test -f /etc/default/fetchmail || exit 0
 . /etc/default/fetchmail

This is redundant with later code that checks if the config file is there and 
gives a more qualified response.

@@ -53,7 +49,7 @@
     if [ ! -r $CONFFILE ] ; then
         log_failure_msg "$CONFFILE not found."
         log_failure_msg "can not start fetchmail daemon... consider disabling 
the script"
-        exit 0
+        exit 6
     fi
 fi

This is the correct exit code when the program is not configured, per LSB.
diff -u fetchmail-6.3.9~rc2/debian/init fetchmail-6.3.9~rc2/debian/init
--- fetchmail-6.3.9~rc2/debian/init
+++ fetchmail-6.3.9~rc2/debian/init
@@ -31,16 +31,12 @@
 PIDFILE="/var/run/fetchmail/fetchmail.pid"
 UIDL="/var/lib/fetchmail/.fetchmail-UIDL-cache"
 
-if [ ! -e $CONFFILE ]; then
-    exit 0
-fi
-
 test -f /etc/default/fetchmail || exit 0
 . /etc/default/fetchmail
 
 OPTIONS="$OPTIONS -f $CONFFILE --pidfile $PIDFILE"
 
-if [ ! "x$START_DAEMON" = "xyes" -a ! "$1" = "stop" ]; then
+if [ ! "x$START_DAEMON" = "xyes" -a ! "$1" = "stop" -a ! "$1" = "status" ]; then
 	echo "Edit /etc/default/fetchmail to start fetchmail"
 	exit 0
 fi
@@ -53,7 +49,7 @@
     if [ ! -r $CONFFILE ] ; then
         log_failure_msg "$CONFFILE not found."
         log_failure_msg "can not start fetchmail daemon... consider disabling the script"
-        exit 0
+        exit 6
     fi
 fi
 
@@ -91,7 +87,7 @@
 fi
 
 # support for ephemeral /var/run
-if [ "${PIDFILE%/*}" = "/var/run/fetchmail" ] && [ ! -d ${PIDFILE%/*} ]; then
+if [ "${PIDFILE%/*}" = "/var/run/fetchmail" ] && [ ! -d ${PIDFILE%/*} ] && [ "$1" != "status" ]; then
 	mkdir /var/run/fetchmail
 	chown -h $USER:nogroup /var/run/fetchmail
 	chmod 700 /var/run/fetchmail
@@ -115,7 +111,7 @@
 #fi
 
 # Makes sure certain files/directories have the proper owner
-if [ "`stat -c '%U %a' $CONFFILE 2>/dev/null`" != "$USER 600" ]; then
+if [ -f $CONFFILE -a  "`stat -c '%U %a' $CONFFILE 2>/dev/null`" != "$USER 600" ]; then
 	chown -h $USER $CONFFILE
 	chmod -f 0600 $CONFFILE
 fi
@@ -219,6 +215,9 @@
 		echo "$0: End of service run. Exit status was: $?"
 		exit 0
 		;;
+	status)
+		status_of_proc $DAEMON fetchmail -p $PIDFILE
+		;;
 	*)
 		log_warning_msg "Usage: /etc/init.d/fetchmail {start|stop|restart|force-reload|awaken|debug-run}"
 		log_warning_msg "  start - starts system-wide fetchmail service"
diff -u fetchmail-6.3.9~rc2/debian/control fetchmail-6.3.9~rc2/debian/control
--- fetchmail-6.3.9~rc2/debian/control
+++ fetchmail-6.3.9~rc2/debian/control
@@ -11,7 +11,7 @@
 
 Package: fetchmail
 Architecture: any
-Depends: ${shlibs:Depends}, debianutils (>= 1.7), adduser (>= 3.34), lsb-base (>= 3.0-6)
+Depends: ${shlibs:Depends}, debianutils (>= 1.7), adduser (>= 3.34), lsb-base (>= 3.2-13)
 Conflicts: fetchmail-common, logcheck (<< 1.1.1-9), fetchmail-ssl (<= 6.2.5-12)
 Replaces: fetchmail-common, fetchmail-ssl
 Provides: fetchmail-ssl

Reply via email to