Code

init.d: Use log_* and status_of_proc functions from LSB's init functions.
authorSebastian Harl <sh@tokkee.org>
Sat, 30 Jun 2012 11:19:42 +0000 (13:19 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 30 Jun 2012 11:19:42 +0000 (13:19 +0200)
… in order to make collectd's output look like all the other output.
Thanks to Matthias Urlichs for pointing this out.
Closes: #679355
debian/changelog
debian/collectd-core.collectd.init.d

index 034d54db4086930f675795550c84dad9f8d65658..a1d55fb89c649b9df7a7d13a209066ae55a023b5 100644 (file)
@@ -31,6 +31,9 @@ collectd (5.1.0-2) UNRELEASED; urgency=low
     - Source /lib/lsb/init-functions in order to make systemd work in
       compatibility mode; thanks to Michael Stapelberg for reporting this
       (Closes: #679544).
+    - Use log_* and status_of_proc functions from LSB's init functions to
+      make collectd's output look like all the other output; thanks to
+      Matthias Urlichs for pointing this out (Closes: #679355).
 
  -- Sebastian Harl <tokkee@debian.org>  Fri, 29 Jun 2012 22:17:27 +0200
 
index 70399811eaa72dd2d41bda2f98a598198e08b024..991d8b8a17f35a356b76708e35139ac6c77d5e39 100755 (executable)
@@ -51,12 +51,12 @@ if [ -r /etc/default/$NAME ]; then
 fi
 
 if test "$DISABLE" != 0 -a "$1" == "start"; then
-       echo "$NAME has been disabled - see /etc/default/$NAME."
+       log_warning_msg "Not starting $DESC, disabled by /etc/default/$NAME."
        exit 0
 fi
 
 if test ! -e "$CONFIGFILE" -a "$1" == "start"; then
-       echo "Not starting $NAME - no configuration ($CONFIGFILE) found."
+       log_warning_msg "Not starting $DESC, no configuration ($CONFIGFILE) found."
        exit 0
 fi
 
@@ -72,34 +72,38 @@ fi
 
 check_config() {
        if ! $DAEMON -t -C "$CONFIGFILE"; then
-               if test -n "$1"; then
-                       echo "$1" >&2
-               fi
-               exit 1
+               return 1
        fi
 }
 
 d_start() {
        if test "$DISABLE" != 0; then
                # we get here during restart
-               echo -n " - disabled by /etc/default/$NAME"
-               return 0
+               log_progress_msg "disabled by /etc/default/$NAME"
+               return 2
        fi
 
        if test ! -e "$CONFIGFILE"; then
                # we get here during restart
-               echo -n " - no configuration ($CONFIGFILE) found."
-               return 0
+               log_progress_msg "disabled, no configuration ($CONFIGFILE) found"
+               return 2
        fi
 
        check_config
+       rc="$?"
+       if test "$rc" -eq 1; then
+               log_progress_msg "not starting, configuration error"
+               return 2
+       fi
 
        if test "$USE_COLLECTDMON" == 1; then
                start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
-                       --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE"
+                       --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE" \
+                       || return 2
        else
                start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
-                       --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE"
+                       --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE" \
+                       || return 2
        fi
 }
 
@@ -112,6 +116,11 @@ d_stop() {
        PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
 
        start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
+       rc="$?"
+
+       if test "$rc" -eq 2; then
+               return 2
+       fi
 
        sleep 1
        if test -n "$PID" && kill -0 $PID 2> /dev/null; then
@@ -121,66 +130,66 @@ d_stop() {
                        echo -n " ."
 
                        if test $i -gt $MAXWAIT; then
-                               echo "$still_running_warning" >&2
-                               return 1
+                               log_progress_msg "$still_running_warning"
+                               return 2
                        fi
 
                        sleep 2
                done
-               return 0
+               return "$rc"
        fi
-}
-
-d_status() {
-       PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
-
-       if test -n "$PID" && kill -0 $PID 2> /dev/null; then
-               echo "collectd ($PID) is running."
-               exit 0
-       else
-               PID=$( pidof collectd ) || true
-
-               if test -n "$PID"; then
-                       echo "collectd ($PID) is running."
-                       exit 0
-               else
-                       if test -f "$_PIDFILE"; then
-                               echo "collectd is stopped but PID file exists."
-                               exit 1
-                       fi
-                       echo "collectd is stopped."
-                       exit 3
-               fi
-       fi
-       echo "status of collectd unknown."
-       exit 4
+       return "$rc"
 }
 
 case "$1" in
        start)
-               echo -n "Starting $DESC: $NAME"
+               log_daemon_msg "Starting $DESC" "$NAME"
                d_start
-               echo "."
+               case "$?" in
+                       0|1) log_end_msg 0 ;;
+                       2) log_end_msg 1 ;;
+               esac
                ;;
        stop)
-               echo -n "Stopping $DESC: $NAME"
+               log_daemon_msg "Stopping $DESC" "$NAME"
                d_stop
-               echo "."
+               case "$?" in
+                       0|1) log_end_msg 0 ;;
+                       2) log_end_msg 1 ;;
+               esac
                ;;
        status)
-               d_status
+               status_of_proc -p "$_PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
                ;;
        restart|force-reload)
-               echo -n "Restarting $DESC: $NAME"
-               check_config "Not restarting collectd."
+               log_daemon_msg "Restarting $DESC" "$NAME"
+               check_config
+               rc="$?"
+               if test "$rc" -eq 1; then
+                       log_progress_msg "not restarting, configuration error"
+                       log_end_msg 1
+                       exit 1
+               fi
                d_stop
-               sleep 1
-               d_start
-               echo "."
+               rc="$?"
+               case "$rc" in
+                       0|1)
+                               sleep 1
+                               d_start
+                               rc2="$?"
+                               case "$rc2" in
+                                       0) log_end_msg 0 ;;
+                                       *) log_end_msg 1 ;;
+                               esac
+                               ;;
+                       *)
+                               log_end_msg 1
+                               ;;
+               esac
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
-               exit 1
+               exit 3
                ;;
 esac