[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#718798: cups-daemon: suggestions for init script: bashisms, lsb...



Package: cups-daemon
Version: 1.6.2-10
Severity: minor
Tags: patch

Hello. Please consider the attached changes, inspired by
/etc/init.d/skeleton and
http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html.
The skeleton may suggest many other easy improvements in calls to
start-stop-daemon, but I lack knowledge of CUPS to decide such
changes.

Comments, roughly in the order of the attached diff:

SCRIPTNAME replaces N=${0##*/}. This construct is specific to bash,
while init scripts may be executed by sh.

Include /lib/init/vars.sh and respect VERBOSE when appropriate.

Replace restart_xprint() implicit parameter (success) with an explicit
first parameter for readability.

log_daemon_msg() should be used instead of log_begin_msg(). The former
wraps the latter with vendor-specific formatting.

I tryed to clarify the exit status handling. For example: in start),
the displayed $? was the one of coldplug_usb_printers instead of the
one from start-stop-daemon.

coldplug_usb_printer was called even if in case of failure to start
the daemon. I changed this, but maybe this was wanted.

status_of_proc() replaces hand-written status reporting, with a more
accurate selection of non-zero exit statuses. It needs lsb-base (>=
3.2-14).

Unimplemented actions must return 3.
diff --git a/debian/control b/debian/control
index 549219d..f1c333a 100644
--- a/debian/control
+++ b/debian/control
@@ -142,7 +142,7 @@ Depends: ${shlibs:Depends},
  poppler-utils (>= 0.12),
  procps,
  ghostscript (>= 9.02~),
- lsb-base (>= 3),
+ lsb-base (>= 3.2-14),
  cups-common (>= ${source:Version}),
  cups-server-common (>= ${source:Version}),
  cups-client (>= ${binary:Version}),
diff --git a/debian/cups-daemon.cups.init b/debian/cups-daemon.cups.init
index 06a6d8f..de25cee 100644
--- a/debian/cups-daemon.cups.init
+++ b/debian/cups-daemon.cups.init
@@ -14,22 +14,33 @@
 #                    make it's web interface accessible on http://localhost:631/
 ### END INIT INFO
 
+# Author: Debian Printing Team <debian-printing@lists.debian.org>
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/usr/sbin/cupsd
 NAME=cupsd
 PIDFILE=/var/run/cups/$NAME.pid
 DESC="Common Unix Printing System"
+SCRIPTNAME=/etc/init.d/cups
 
 unset TMPDIR
 
+# Exit if the package is not installed
 test -x $DAEMON || exit 0
 
 mkdir -p /var/run/cups/certs
 
+# Read configuration variable file if it is present
 if [ -r /etc/default/cups ]; then
   . /etc/default/cups
 fi
 
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
 . /lib/lsb/init-functions
 
 # Get the timezone set.
@@ -38,8 +49,9 @@ if [ -z "$TZ" -a -e /etc/timezone ]; then
     export TZ
 fi
 
+# Only effective if first parameter = 0.
 restart_xprint() {
-    if [ -n "$success" ] && [ -x /etc/init.d/xprint ]; then
+    if [ "$1" = 0 ] && [ -x /etc/init.d/xprint ]; then
         invoke-rc.d xprint force-reload || true
     fi
 }
@@ -57,7 +69,7 @@ coldplug_usb_printers() {
 
 case "$1" in
   start)
-	log_begin_msg "Starting $DESC: $NAME"
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
 	mkdir -p `dirname "$PIDFILE"`
 	if [ "$LOAD_LP_MODULE" = "yes" -a -f /usr/lib/cups/backend/parallel \
@@ -67,50 +79,41 @@ case "$1" in
 	  modprobe -q -b parport_pc || true
 	fi
 
-	start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" --exec $DAEMON && success=1
-
-	coldplug_usb_printers
-	log_end_msg $?
-	restart_xprint
+	start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" --exec $DAEMON
+	status=$?
+	[ $status = 0 ] && coldplug_usb_printers
+	[ "$VERBOSE" != no ] && log_end_msg $status
+	restart_xprint $status
 	;;
   stop)
-	log_begin_msg "Stopping $DESC: $NAME"
-	start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME && success=1
-	log_end_msg $?
-	restart_xprint
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME
+	status=$?
+	[ "$VERBOSE" != no ] && log_end_msg $status
+	restart_xprint $status
 	;;
   reload|force-reload)
-       log_begin_msg "Reloading $DESC: $NAME"
-       start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --signal 1 && success=1
-       log_end_msg $?
-	restart_xprint
+       log_daemon_msg "Reloading $DESC" "$NAME"
+       start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --signal 1
+       status=$?
+       log_end_msg $status
+       restart_xprint $status
        ;;
   restart)
-	log_begin_msg "Restarting $DESC: $NAME"
+	log_daemon_msg "Restarting $DESC" "$NAME"
 	if start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME; then
-		start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec $DAEMON && success=1
+		start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec $DAEMON
 	fi
-	log_end_msg $?
-	restart_xprint
+	status=$?
+	log_end_msg $status
+	restart_xprint $status
 	;;
   status)
-	echo -n "Status of $DESC: "
-	if [ ! -r "$PIDFILE" ]; then
-		echo "$NAME is not running."
-		exit 3
-	fi
-	if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
-		echo "$NAME is running."
-		exit 0
-	else
-		echo "$NAME is not running but $PIDFILE exists."
-		exit 1
-	fi
+	status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
 	;;
   *)
-	N=/etc/init.d/${0##*/}
-	echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
-	exit 1
+	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
+	exit 3
 	;;
 esac
 

Reply to: