From jnlin@tamama.org  Fri Dec 28 10:10:32 2007
Return-Path: <jnlin@tamama.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 9203816A421;
	Fri, 28 Dec 2007 10:10:32 +0000 (UTC)
	(envelope-from jnlin@tamama.org)
Received: from Florence.tamama.org (Florence.tamama.org [59.120.212.55])
	by mx1.freebsd.org (Postfix) with ESMTP id 1176813C4D1;
	Fri, 28 Dec 2007 10:10:32 +0000 (UTC)
	(envelope-from jnlin@tamama.org)
Received: by Florence.tamama.org (Postfix, from userid 1000)
	id 05D4EC7FC; Fri, 28 Dec 2007 17:55:18 +0800 (CST)
Message-Id: <20071228095518.05D4EC7FC@Florence.tamama.org>
Date: Fri, 28 Dec 2007 17:55:18 +0800 (CST)
From: Jui-Nan Lin <jnlin@csie.nctu.edu.tw>
To: FreeBSD-gnats-submit@freebsd.org
Cc: brooks@FreeBSD.org
Subject: [PATCH] sysutils/ganglia-monitor-core: allow to run multiple gmond
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         119095
>Category:       ports
>Synopsis:       [PATCH] sysutils/ganglia-monitor-core: allow to run multiple gmond
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 28 10:20:01 UTC 2007
>Closed-Date:    Fri Jan 30 23:09:49 UTC 2009
>Last-Modified:  Fri Jan 30 23:09:49 UTC 2009
>Originator:     Jui-Nan Lin
>Release:        FreeBSD 6.2-RELEASE-p9 i386
>Organization:
>Environment:
System: FreeBSD Florence.tamama.org 6.2-RELEASE-p9 FreeBSD 6.2-RELEASE-p9 #0: Fri Nov 30 03:13:43 CST 2007
>Description:

In our environment, we needed to gather data of multiple clusters in one node. 
Since a gmond reports only 1 cluster name to gmetad, we have to run multiple gmond instances.
I have modified the rc script to allow this feature. The old usage is also work correctly.

Port maintainer (brooks@FreeBSD.org) is cc'd.

Generated with FreeBSD Port Tools 0.77
>How-To-Repeat:
>Fix:

--- ganglia-monitor-core-3.0.6_1.patch begins here ---
diff -ruN --exclude=CVS /usr/ports/sysutils/ganglia-monitor-core/Makefile /home/jnlin/ports/ganglia-monitor-core/Makefile
--- /usr/ports/sysutils/ganglia-monitor-core/Makefile	Tue Dec 18 06:24:48 2007
+++ /home/jnlin/ports/ganglia-monitor-core/Makefile	Fri Dec 28 15:44:27 2007
@@ -7,6 +7,7 @@
 
 PORTNAME=	monitor-core
 PORTVERSION=	3.0.6
+PORTREVISION=	1
 CATEGORIES=	sysutils net parallel
 MASTER_SITES=	${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=	ganglia
diff -ruN --exclude=CVS /usr/ports/sysutils/ganglia-monitor-core/files/gmond.sh.in /home/jnlin/ports/ganglia-monitor-core/files/gmond.sh.in
--- /usr/ports/sysutils/ganglia-monitor-core/files/gmond.sh.in	Fri Jul 14 05:52:02 2006
+++ /home/jnlin/ports/ganglia-monitor-core/files/gmond.sh.in	Fri Dec 28 15:44:26 2007
@@ -11,15 +11,107 @@
 name=gmond
 rcvar=`set_rcvar`
 command="%%PREFIX%%/sbin/${name}"
+start_cmd="gmond_start"
+stop_cmd="gmond_stop"
+
+# init_variables _j
+#       Initialize the various gmond variables for gmond _j.
+#
+init_variables()
+{
+	_j="$1"
+
+	if [ -z "$_j" ]; then
+		warn "init_variables: you must specify a gmond"
+		return
+	fi
+
+	eval _conf=\"\$gmond_${_j}_conf\"
+	if [ -z "$_conf" ]; then
+		_conf="%%PREFIX%%/etc/gmond.conf"
+	fi		
+}
+
+start_instance()
+{
+        if [ "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
+		echo -n " [${_gmond} already running (${pidfile} exists)]"
+                continue
+        fi
+	if [ ! -f $_conf ]; then
+		echo -n " [Cannot found ${_conf}]"
+                continue
+	fi	
+
+	echo -n " $_gmond"
+	${command} -c ${_conf} -p ${pidfile}
+}
+
+stop_instance()
+{
+      if [ -f $pidfile ]; then
+		pid=`cat $pidfile`
+		kill $pid	
+		rm $pidfile
+		echo -n " $_gmond"
+      fi
+}
+
+gmond_start()
+{
+	# For Backward Compatability
+	if [ -z "${gmond_list}" ]; then
+		_conf="$gmond_conf"
+		if [ -z "$_conf" ]; then
+			_conf="%%PREFIX%%/etc/gmond.conf"
+		fi		
+		echo -n 'Starting gmond'
+		_gmond=""
+		pidfile="/var/run/gmond.pid"
+		start_instance
+	else	
+		echo -n 'Starting gmonds:'
+		for _gmond in ${gmond_list}
+		do
+			init_variables $_gmond
+			pidfile="/var/run/gmond_${_gmond}.pid"	
+			start_instance	
+		done	
+	fi
+	echo '.'	
+}	
+
+gmond_stop()
+{
+	# For Backward Compatability
+	if [ -z "${gmond_list}" ]; then
+		echo -n 'Stopping gmond'
+		_gmond="."
+		pidfile="/var/run/gmond.pid"
+		stop_instance
+	else	
+		echo -n 'Stopping gmonds:'
+		for _gmond in ${gmond_list}
+		do
+			pidfile="/var/run/gmond_${_gmond}.pid"	
+			stop_instance	
+		done	
+	fi	
+	echo '.'	
+}	
+
 
 load_rc_config ganglia
 
 load_rc_config $name
+cmd="$1"
 
-gmond_enable=${gmond_enable-NO}
-gmond_conf=${gmond_conf-%%PREFIX%%/etc/gmond.conf}
+if [ $# -gt 0 ]; then
+	shift
+fi
 
-command_args="-c ${gmond_conf}"
-required_files=${gmond_conf}
+if [ -n "$*" ]; then
+	gmond_list="$*"
+fi
+run_rc_command "${cmd}"
 
-run_rc_command $*
--- ganglia-monitor-core-3.0.6_1.patch ends here ---

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->brooks 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Fri Dec 28 10:20:09 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119095 
State-Changed-From-To: open->closed 
State-Changed-By: brooks 
State-Changed-When: Fri Jan 30 23:05:36 UTC 2009 
State-Changed-Why:  
Thank you for your submission.  After a much consideration, I have 
decided to not accept this change.  My reason is that it adds 
significant complexity to the script and handle and edge case.  I 
would suggest either maintaining it as a local patch for your 
environment or simply making multiple, slightly modfied copied of 
the start script for each instance. 

I think that the best location for a change like this would be in 
/etc/rc.subr so every script could potentially benefit.  I'm not 
sure such a submission would be accepted, but if it were sufficently 
clean I think there would be a decent chance. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119095 
>Unformatted:
