<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,8 @@
 #!/bin/bash
 # puppetmaster  This shell script enables the puppetmaster server.
 #
-# Author:       Duane Griffin &lt;d.griffin@psenterprise.com&gt;
+# Authors:       Duane Griffin &lt;d.griffin@psenterprise.com&gt;
+#                Peter Meier &lt;peter.meier@immerda.ch&gt; (Mongrel enhancements)
 #
 # chkconfig: - 65 45
 #
@@ -22,6 +23,13 @@ fi
 
 PUPPETMASTER_OPTS=&quot;&quot;
 [ -n &quot;$PUPPETMASTER_MANIFEST&quot; ] &amp;&amp; PUPPETMASTER_OPTS=&quot;--manifest=${PUPPETMASTER_MANIFEST}&quot;
+multiport=no
+if [ -n &quot;$PUPPETMASTER_PORTS&quot; ] &amp;&amp; [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ]; then
+    multiport=yes 
+    PUPPETMASTER_OPTS=&quot;$PUPPETMASTER_OPTS --servertype=mongrel&quot;
+elif [ -n &quot;$PUPPETMASTER_PORTS&quot; ] &amp;&amp; [ ${#PUPPETMASTER_PORTS[@]} -eq 1 ]; then
+    PUPPETMASTER_OPTS=&quot;${PUPPETMASTER_OPTS} --masterport=${PUPPETMASTER_PORTS[0]}&quot; 
+fi
 [ -n &quot;$PUPPETMASTER_LOG&quot; ] &amp;&amp; PUPPETMASTER_OPTS=&quot;${PUPPETMASTER_OPTS} --logdest=${PUPPETMASTER_LOG}&quot;
 PUPPETMASTER_OPTS=&quot;${PUPPETMASTER_OPTS} \
 	${PUPPETMASTER_EXTRA_OPTS}&quot;
@@ -36,8 +44,16 @@ start() {
 
 	# Confirm the manifest exists
 	if [ -r $PUPPETMASTER_MANIFEST ]; then
-		daemon $PUPPETMASTER $PUPPETMASTER_OPTS
-		RETVAL=$?
+        if [ $multiport = yes ]; then
+            for ((i=0; i&lt;${#PUPPETMASTER_PORTS[@]}; i++)); do
+                echo -en &quot;\nPort: ${PUPPETMASTER_PORTS[$i]}&quot;
+                daemon $PUPPETMASTER $PUPPETMASTER_OPTS --masterport=${PUPPETMASTER_PORTS[$i]} --pidfile=/var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid
+                ret=$?; [ $ret != 0 ] &amp;&amp; RETVAL=$ret
+            done
+        else
+            daemon $PUPPETMASTER $PUPPETMASTER_OPTS
+            RETVAL=$?
+        fi
 	else
 		failure $&quot;Manifest does not exist: $PUPPETMASTER_MANIFEST&quot;
 		echo
@@ -50,8 +66,16 @@ start() {
 
 stop() {
 	echo -n  $&quot;Stopping puppetmaster: &quot;
-	killproc $PUPPETMASTER
-	RETVAL=$?
+    if [ $multiport = yes ]; then
+        for ((i=0; i&lt;${#PUPPETMASTER_PORTS[@]}; i++)); do
+            echo -en &quot;\nPort: ${PUPPETMASTER_PORTS[$i]}&quot;
+            killproc -p /var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid puppetmaster 
+            ret=$?; [ $ret != 0 ] &amp;&amp; RETVAL=$ret
+        done
+    else
+       killproc $PUPPETMASTER
+       RETVAL=$?
+    fi
 	echo
 	[ $RETVAL -eq 0 ] &amp;&amp; rm -f &quot;$lockfile&quot;
 	return $RETVAL
@@ -67,6 +91,20 @@ genconfig() {
   $PUPPETMASTER $PUPPETMASTER_OPTS --genconfig
 }
 
+puppetmaster_status() {
+    if [ $multiport = yes ]; then
+        for ((i=0; i&lt;${#PUPPETMASTER_PORTS[@]}; i++)); do
+            echo -en &quot;Port ${PUPPETMASTER_PORTS[$i]}: &quot;
+            status -p /var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid puppetmaster 
+            ret=$?; [ $ret != 0 ] &amp;&amp; RETVAL=$ret
+        done 
+    else
+	    status $PUPPETMASTER
+        RETVAL=$?
+    fi
+    return $RETVAL
+}
+
 case &quot;$1&quot; in
   start)
 	start
@@ -81,8 +119,7 @@ case &quot;$1&quot; in
 	[ -f &quot;$lockfile&quot; ] &amp;&amp; restart
 	;;
   status)
-	status $PUPPETMASTER
-        RETVAL=$?
+    puppetmaster_status
 	;;
   genconfig)
 	genconfig</diff>
      <filename>conf/redhat/server.init</filename>
    </modified>
    <modified>
      <diff>@@ -5,5 +5,27 @@
 # Specify syslog to send log messages to the system log.
 #PUPPETMASTER_LOG=syslog
 
+# You may specify an alternate port or an array of ports on which 
+# puppetmaster should listen. Default is: 8140
+# If you specify more than one port, the puppetmaster ist automatically
+# started with the servertype set to mongrel. This might be interesting
+# if you'd like to run your puppetmaster in a loadbalanced cluster.
+# Please note: this won't setup nor start any loadbalancer. 
+# If you'd like to run puppetmaster with mongrel as servertype but only
+# on one (specified) port, you have to add --servertype=mongrel to
+# PUPPETMASTER_EXTRA_OPTS.
+# Default: Empty (Puppetmaster isn't started with mongrel, nor on a 
+# specific port)
+#
+# Please note: Due to reduced options in the rc-functions lib in RHEL/Centos
+# versions prior to 5, this feature won't work. Fedora versions &gt;= 8 are 
+# known to work.
+#PUPPETMASTER_PORTS=&quot;&quot;
+# Puppetmaster on a different port, run with standard webrick servertype
+#PUPPETMASTER_PORTS=&quot;8141&quot;
+# Example with multiple ports which will start puppetmaster with mongrel
+# as a servertype
+#PUPPETMASTER_PORTS=( 18140 18141 18142 18143 )
+
 # You may specify other parameters to the puppetmaster here
 #PUPPETMASTER_EXTRA_OPTS=--noca</diff>
      <filename>conf/redhat/server.sysconfig</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a74ec60d33dee1c592ec858faeccc23d7a7b79f3</id>
    </parent>
  </parents>
  <author>
    <name>duritong</name>
    <email>peter.meier@immerda.ch</email>
  </author>
  <url>http://github.com/duritong/puppet/commit/0e03ffe48a43cb6f22eb77497ae3042a4a97abdf</url>
  <id>0e03ffe48a43cb6f22eb77497ae3042a4a97abdf</id>
  <committed-date>2008-10-18T04:02:48-07:00</committed-date>
  <authored-date>2008-10-18T04:02:48-07:00</authored-date>
  <message>enhance redhat puppetmaster init.d script to easy start puppetmaster as a
mongrel cluster v2.1

If you'd like to run puppetmaster in a mongrel cluster you have to start X

instances of puppetmaster with servertype set to mongrel. With this patch
you can add more than one port to the sysconfig file and puppetmaster will

automatically be started with severtype set to mongrel.
You can now even specify an alternate port in the sysconfig file on which
puppetmaster should be run as webrick based server. See sysconfig file for

more documentation.

This is the second version of this patch and it adresses some comments
which have been made by David Lutterkort on Ticket #1460:

- there's no need to introduce PUPPETMASTER_PID_DIR as a variable in
  sysconfig

removed.

- the way RETVAL is accumulated (RETVAL=$? || $RETVAL) is wrong;
  it needs to be 'ret=$?; [ $ret != 0 ] &amp;&amp; RETVAL=$ret'

fixed.

- make sure that 'status' still works and lists all the instances in
  the multiport case (similar to 'service nfs status')

added.

v2.1:

addressed changing [ -n &quot;$PUPPETMASTER_PORTS&quot; ] &amp;&amp; [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ] to [ $multiport = yes</message>
  <tree>1149edc551ab8c6f92e2fa332b3dd10eda8abc3e</tree>
  <committer>
    <name>duritong</name>
    <email>peter.meier@immerda.ch</email>
  </committer>
</commit>
