Package: mpd
Version: 0.13.0-2
Severity: minor
Tags: patch

The init script for the mpd package does not yet conform to LSB 
guidelines.

I have followed <URL:http://wiki.debian.org/LSBInitScripts> and edited
'debian/mpd.init.d' to be closer to a standard LSB init script. The 
attached patch is against version 0.13.0-2 of the mpd package.

In particular, this patch addresses the following:

  * a standard init script metadata block

  * using just the shell program name in the shebang line, and setting 
    options within the script with the 'set' command (not part of LSB, 
    but a move to make this a more-standard init script)

  * using only the LSB log_foo_msg functions for init script output

  * using standard init script exit status codes: 0 for success, 1 for 
    failure, 2 for usage message

=== modified file 'debian/mpd.init.d'
--- old/debian/mpd.init.d	2007-12-29 05:02:26 +0000
+++ new/debian/mpd.init.d	2007-12-29 05:41:51 +0000
@@ -1,5 +1,19 @@
-#!/bin/sh -e
-
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:          mpd
+# Required-Start:    $syslog $local_fs
+# Required-Stop:     $syslog $local_fs
+# Should-Start:      $network
+# Should-Stop:       $network
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Music Player Daemon
+# Description:       Start the Music Player Daemon (MPD) service
+#                    for network access to the local audio queue.
+### END INIT INFO
+
+set -e
 if [ -n "$MPD_DEBUG" ]; then
     set -x
     MPD_OPTS=--verbose
@@ -8,6 +22,9 @@
 umask 0022
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+. /lib/lsb/init-functions
+
 NAME=mpd
 DESC="Music Player Daemon"
 DAEMON=/usr/bin/mpd
@@ -18,21 +35,23 @@
 [ -x "$DAEMON" ] || exit 0
 
 # Read configuration variable file if it is present
-[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+default_conf=/etc/default/$NAME
+[ -r $default_conf ] && . $default_conf
 
 PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
 DBFILE=$(sed -n 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
 
 mpd_start () {
+    log_daemon_msg "Starting $DESC" "$NAME"
+
     if [ "$START_MPD" != "true" ]; then
-        echo "Not starting MPD: disabled by /etc/default/mpd."
-        exit 0
+        log_failure_msg "Not starting MPD: disabled by '$default_conf'."
+        exit 1
     fi
-    echo -n "Starting $DESC: "
 
     if ! (grep -q db_file $MPDCONF && grep -q pid_file $MPDCONF); then
-        echo "$MPDCONF must have db_file and pid_file set; not starting."
-        exit 0
+        log_failure_msg "$MPDCONF must have db_file and pid_file set; not starting."
+        exit 1
     fi
 
     PIDDIR=$(dirname "$PIDFILE")
@@ -42,26 +61,20 @@
     fi
 
     if [ "$FORCE_CREATE_DB" -o ! -f "$DBFILE" ]; then
-        echo -n "creating $DBFILE... "
+        log_warning_msg "creating $DBFILE... "
         $DAEMON --create-db "$MPDCONF" > /dev/null 2>&1
     fi
 
-    if start-stop-daemon --start --quiet --pidfile $PIDFILE \
-            --exec $DAEMON $MPD_OPTS "$MPDCONF"; then
-        echo "$NAME."
-    else
-        echo "failed."
-    fi
+    start-stop-daemon --start --quiet --pidfile $PIDFILE \
+        --exec $DAEMON $MPD_OPTS "$MPDCONF"
+    log_end_msg $?
 }
 
 mpd_stop () {
-    echo -n "Stopping $DESC: "
-    if start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE \
-            --exec $DAEMON; then
-        echo "$NAME."
-    else
-        echo "not running or no pid_file set."
-    fi
+    log_daemon_msg "Stopping $DESC" "$NAME"
+    start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE \
+        --exec $DAEMON
+    log_end_msg $?
 }
 
 # note to self: don't call the non-standard args for this in
@@ -89,6 +102,6 @@
         ;;
     *)
         echo "Usage: $0 {start|start-create-db|stop|restart|reload}"
-        exit 1
+        exit 2
         ;;
 esac

Reply via email to