Holger Levsen <[email protected]> writes:

>> > (*) I'm also not sure if I think adding yet another file to /etc/default/
>> > is sensible, as just the same can be achieved with update-rc.d.
>> The file /etc/default/munin-node was already there in the init.d script.
>
> it was just never used nor documented, afaics.

With ENABLED, the default installation can be kept untouched. Similar
construct is in use e.g. in:

  /etc/default/icecast2:ENABLE=false
  /etc/default/spamassassin:ENABLED=1
  /etc/default/rsync:RSYNC_ENABLE=false
  /etc/default/bootlogd:BOOTLOGD_ENABLE=No

Patches below against SVN r1862

Jari

>From 0b5a1425bb921dd8d2653f4725e3bf7a42630456 Mon Sep 17 00:00:00 2001
From: Jari Aalto <[email protected]>
Date: Sat, 7 Mar 2009 21:04:53 +0200
Subject: [PATCH] munin-node.init: Rewrite to pure /bin/sh

Signed-off-by: Jari Aalto <[email protected]>
---
 munin-node.init |  214 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 123 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..4f5559b
--- 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,8 @@ 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
+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 +26,59 @@ 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 [ ! -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 +93,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 +117,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 +162,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

This is applied after the above one

>From 9f526a3987088f27dd5c482d6d05a79b25a710cf Mon Sep 17 00:00:00 2001
From: Jari Aalto <[email protected]>
Date: Sat, 7 Mar 2009 21:41:00 +0200
Subject: [PATCH] munin-node.init: Add ENABLED. munin-node.default: new. NEWS: document /etc/default/munin-node.

Signed-off-by: Jari Aalto <[email protected]>
---
 NEWS               |    9 +++++++++
 munin-node.default |    2 ++
 munin-node.init    |   11 +++++++++++
 3 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 munin-node.default

diff --git a/NEWS b/NEWS
index 4afdb3f..456205f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+munin (1.2.6-3) unstable; urgency=low
+
+  * The /etc/init.d/munin-no script sources file /etc/default/munin-node if
+    it exists. If variable ENABLE is set to anything else than 1 or 'true'
+    or 'yes', the init.d script is not run. This allow controlling that
+    activation of script with a single variable.
+
+ -- Jari Aalto <[email protected]>  Sat, 07 Mar 2009 21:19:00 +0200
+
 munin (1.2.6-2) unstable; urgency=low
 
   * Build the binary package 'munin-plugins-extra' with user contributed
diff --git a/munin-node.default b/munin-node.default
new file mode 100644
index 0000000..60afd99
--- /dev/null
+++ b/munin-node.default
@@ -0,0 +1,2 @@
+# Uncommend to disable /etc/init.d/munin-node script (not to start at boot)
+# ENABLED="no"
diff --git a/munin-node.init b/munin-node.init
index 4f5559b..28256f8 100755
--- a/munin-node.init
+++ b/munin-node.init
@@ -18,6 +18,7 @@ PIDFILE=/var/run/munin/munin-node.pid
 CONFFILE=/etc/munin/munin-node.conf
 DESC="Munin Network Grapher"
 CONFDEFAULT=/etc/default/munin-node
+ENABLED="yes"
 
 # 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-
@@ -47,6 +48,16 @@ log_progress_msg () {
 . /lib/lsb/init-functions
 [ -r $CONFDEFAULT ] && . $CONFDEFAULT
 
+if [ "$ENABLED" = "yes"  ] ||
+   [ "$ENABLED" = "true" ] ||
+   [ "$ENABLED" = "1"    ]
+then
+    :
+else
+    echo "$DESC: disabled, see ENABLED option in $CONFDEFAULT"
+    exit 0
+fi
+
 if [ ! -x "$DAEMON" ]; then
 	log_failure_msg "Munin-Node appears to be uninstalled."
 	exit 5
-- 
1.6.1.3

Reply via email to