tags patch
thanks
The followin patch against munin-1.2.6-9, fixes bug #518389. It also provides
new ENABLED confguration option to control init.d scrip usage via
/etc/default/munin-node
Tested with
dash -x
posh -x
Jari
>From 846f394e6ef7543def4419a6d45bb6a8d83f306f Mon Sep 17 00:00:00 2001
From: Jari Aalto <[email protected]>
Date: Sat, 7 Mar 2009 19:07:34 +0200
Subject: [PATCH] debian/munin-node.init: Rewrite to pure /bin/sh
Signed-off-by: Jari Aalto <[email protected]>
---
munin-node.init | 222 ++++++++++++++++++++++++++++++++----------------------
1 files changed, 131 insertions(+), 91 deletions(-)
mode change 100644 => 100755 munin-node.init
diff --git a/munin-node.init b/munin-node.init
old mode 100644
new mode 100755
index 8fa0301..0fdc8c9
--- a/munin-node.init
+++ b/munin-node.init
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
### BEGIN INIT INFO
# Provides: munin-node
@@ -16,6 +16,9 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/munin-node
PIDFILE=/var/run/munin/munin-node.pid
CONFFILE=/etc/munin/munin-node.conf
+ENABLED="yes"
+DESC="Munin Network Grapher"
+CONFDEFAULT=/etc/default/munin-node
# log_daemon_msg() and log_progress_msg() isn't present in present in Sarge.
# Below is a copy of them from lsb-base 3.0-5, for the convenience of back-
@@ -24,45 +27,66 @@ CONFFILE=/etc/munin/munin-node.conf
log_daemon_msg () {
if [ -z "$1" ]; then
- return 1
+ return 1
fi
if [ -z "$2" ]; then
- echo -n "$1:"
- return
+ echo -n "$1:"
+ return
fi
-
+
echo -n "$1: $2"
}
log_progress_msg () {
if [ -z "$1" ]; then
- return 1
+ return 1
fi
echo -n " $@"
}
. /lib/lsb/init-functions
-[ -r /etc/default/munin-node ] && . /etc/default/munin-node
+[ -r $CONFDEFAULT ] && . $CONFDEFAULT
+
+if [ "$ENABLED" = "yes" ] || [ "$ENABLED" = "1" ] ; then
+ :
+else
+ echo "$DESC: disabled, see ENABLED option in $CONFDEFAULT"
+ exit 0
+fi
-if [ ! -x $DAEMON ]; then
+if [ ! -x "$DAEMON" ]; then
log_failure_msg "Munin-Node appears to be uninstalled."
exit 5
-elif [ ! -e $CONFFILE ]; then
+elif [ ! -e "$CONFFILE" ]; then
log_failure_msg "Munin-Node appears to be unconfigured."
exit 6
fi
-# Figure out if the pid file is in a non-standard location
-while read line; do
- line=${line%%\#*} # get rid of comments
- set -f
- line=$(echo $line) # get rid of extraneous blanks
- set +f
- if [ "$line" != "${line#pid_file }" ]; then
- PIDFILE=${line#pid_file }
- fi
-done < $CONFFILE
+Pid ()
+{
+ # Figure out if the pid file is in a non-standard location
+ while read line
+ do
+ # Ignore comments and empty lines
+
+ case "$line" in
+ \#*) continue ;;
+ esac
+
+ if [ "$line" = "" ]; then
+ continue
+ fi
+
+ set -- $line
+
+ if [ "$1" = "pid_file" ]; then
+ PIDFILE=$(echo $2 | sed 's/#.*//')
+ break
+ fi
+
+ done < $CONFFILE
+}
verify_superuser() {
action=$1
@@ -77,10 +101,18 @@ start() {
# Work-around for brain-damage in Ubuntu, where /var/run/munin
# vanishes after every reboot.
if [ ! -d /var/run/munin ]; then
- perms=(`/usr/sbin/dpkg-statoverride --list /var/run/munin`)
mkdir /var/run/munin
- chown ${perms[0]:-munin}:${perms[1]:-root} /var/run/munin
- chmod ${perms[2]:-0755} /var/run/munin
+
+ # munin root 0755 /var/run/munin
+ set -- $(/usr/sbin/dpkg-statoverride --list /var/run/munin)
+ user=$1
+ group=$2
+ perm=$3
+
+ chown $user:$group /var/run/munin
+ chmod ${perm:-0755} /var/run/munin
+
+ unset user group perm
fi
if pidofproc -p $PIDFILE $DAEMON >/dev/null; then
log_progress_msg "started beforehand"
@@ -93,7 +125,7 @@ start() {
# started manually
attempts=0
until pidofproc -p $PIDFILE $DAEMON >/dev/null; do
- attempts=$(( $attempts + 1 ))
+ attempts=$(( attempts + 1 ))
sleep 0.05
[ $attempts -lt 20 ] && continue
log_end_msg 1
@@ -138,77 +170,85 @@ stop() {
return $ret
}
-if [ "$#" -ne 1 ]; then
- log_failure_msg "Usage: /etc/init.d/munin-node" \
- "{start|stop|restart|force-reload|try-restart}"
- exit 2
-fi
+Main ()
+{
+ Pid # Set PIDFILE from configuration file
-case "$1" in
- start)
- verify_superuser $1
- start
- exit $?
- ;;
- stop)
- verify_superuser $1
- stop
- exit $?
- ;;
- restart|force-reload)
- verify_superuser $1
- stop || exit $?
- start
- exit $?
- ;;
- try-restart)
- verify_superuser $1
- pidofproc -p $PIDFILE $DAEMON >/dev/null
- if [ $? -eq 0 ]; then
+ if [ "$#" -ne 1 ]; then
+ log_failure_msg "Usage: /etc/init.d/munin-node" \
+ "{start|stop|restart|force-reload|try-restart}"
+ exit 2
+ fi
+
+ case "$1" in
+ start)
+ verify_superuser $1
+ start
+ exit $?
+ ;;
+ stop)
+ verify_superuser $1
+ stop
+ exit $?
+ ;;
+ restart|force-reload)
+ verify_superuser $1
stop || exit $?
start
exit $?
- fi
- log_success_msg "Munin-Node was stopped beforehand and thus not" \
- "restarted."
- exit 0
- ;;
- reload)
- log_failure_msg "The \"reload\" action is not implemented."
- exit 3
- ;;
- status)
- pid=$(pidofproc -p $PIDFILE $DAEMON)
- ret=$?
- pid=${pid% } # pidofproc() supplies a trailing space, strip it
- if [ $ret -eq 0 ]; then
- log_success_msg "Munin-Node is running (PID: $pid)"
+ ;;
+ try-restart)
+ verify_superuser $1
+ pidofproc -p $PIDFILE $DAEMON >/dev/null
+ if [ $? -eq 0 ]; then
+ stop || exit $?
+ start
+ exit $?
+ fi
+ log_success_msg "Munin-Node was stopped beforehand and thus not" \
+ "restarted."
exit 0
- # the LSB specifies that I in this case (daemon dead + pid file exists)
- # should return 1, however lsb-base returned 2 in this case up to and
- # including version 3.1-10 (cf. #381684). Since that bug is present
- # in Sarge, Ubuntu Dapper, and (at the time of writing) Ubuntu Etch,
- # and taking into account that later versions of pidofproc() do not
- # under any circumstance return 2, I'll keep understanding invalid
- # return code for the time being, even though the LSB specifies it is
- # to be used for the situation where the "program is dead and /var/lock
- # lock file exists".
- elif [ $ret -eq 1 ] || [ $ret -eq 2 ]; then
- log_failure_msg "Munin-Node is dead, although $PIDFILE exists."
- exit 1
- elif [ $ret -eq 3 ]; then
- log_warning_msg "Munin-Node is not running."
+ ;;
+ reload)
+ log_failure_msg "The \"reload\" action is not implemented."
exit 3
- fi
- log_warning_msg "Munin-Node status unknown."
- exit 4
- ;;
- *)
- log_failure_msg "Usage: /etc/init.d/munin-node" \
- "{start|stop|restart|force-reload|try-restart}"
- exit 2
- ;;
-esac
-
-log_failure_msg "Unexpected failure, please file a bug."
-exit 1
+ ;;
+ status)
+ pid=$(pidofproc -p $PIDFILE $DAEMON)
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ log_success_msg "Munin-Node is running (PID: $pid)"
+ exit 0
+ # the LSB specifies that I in this case (daemon dead + pid file exists)
+ # should return 1, however lsb-base returned 2 in this case up to and
+ # including version 3.1-10 (cf. #381684). Since that bug is present
+ # in Sarge, Ubuntu Dapper, and (at the time of writing) Ubuntu Etch,
+ # and taking into account that later versions of pidofproc() do not
+ # under any circumstance return 2, I'll keep understanding invalid
+ # return code for the time being, even though the LSB specifies it is
+ # to be used for the situation where the "program is dead and /var/lock
+ # lock file exists".
+ elif [ $ret -eq 1 ] || [ $ret -eq 2 ]; then
+ log_failure_msg "Munin-Node is dead, although $PIDFILE exists."
+ exit 1
+ elif [ $ret -eq 3 ]; then
+ log_warning_msg "Munin-Node is not running."
+ exit 3
+ fi
+ log_warning_msg "Munin-Node status unknown."
+ exit 4
+ ;;
+ *)
+ log_failure_msg "Usage: /etc/init.d/munin-node" \
+ "{start|stop|restart|force-reload|try-restart}"
+ exit 2
+ ;;
+ esac
+
+ log_failure_msg "Unexpected failure, please file a bug."
+ exit 1
+}
+
+Main "$@"
+
+# End of file
--
1.6.1.3