tags 500424 + confirmed, upstream, patch
thanks

Hi,

I can confirm this bug is present - and I have prepared this patch
that fixes it.

I know that technically I am a comaintainer for this package, as part
of the pkg-ruby-extras group, but I'd rather have the maintainer
comment on it, as it includes patches to the upstream code. I would
expect upstream to welcome this patch, but I guess you are more
familiar with it than I am.

I am also including Filipe Lautert, as he participates in Mongrel's
upstream team.

Mongrel accepts user and group arguments by command line, although
they are overriden by those in the configuration file, if any. Now,
mongrel_cluster disregards them, and starts everything as user
www-data - This is done by dropping privileges before calling
mongrel_cluster_ctl (and thus mongrel_rails), so obviously
mongrel_rails cannot set the user. What I am doing here is to call
mongrel_cluster_ctl as root, and drop privileges only in
mongrel_rails. The default configuration will keep starting all
instances as www-data:www-data - Unless they specify user and group.

I intend to upload this as a patch (of course, properly quiltified) if
no comments are received in a week time.

Greetings,

-- 
Gunnar Wolf - gw...@iiec.unam.mx - (+52-55)5623-0154 / 1451-2244
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973  F800 D80E F35A 8BB5 27AF
From 1bc53a2a90db23d5da3f0d28c71d193e674f7f71 Mon Sep 17 00:00:00 2001
From: Gunnar Wolf <gw...@gwolf.org>
Date: Tue, 10 Mar 2009 18:45:24 -0600
Subject: [PATCH] Fix for Debian BTS #500424

---
 bin/mongrel_cluster_ctl     |   10 +++++++---
 debian/mongrel-cluster.init |   12 ++++++++----
 lib/mongrel_cluster/init.rb |    6 +++++-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/bin/mongrel_cluster_ctl b/bin/mongrel_cluster_ctl
index 380a18e..602ebac 100755
--- a/bin/mongrel_cluster_ctl
+++ b/bin/mongrel_cluster_ctl
@@ -3,12 +3,14 @@
 
 require 'optparse'
 
-def run(command, verbose, clean=false)
+def run(command, verbose, clean=false, user=nil, group=nil)
   Dir.chdir @options[:conf_path] do
     confs =  Dir.glob("*.yml")
     confs += Dir.glob("*.conf")
     confs.each do |conf|
       cmd = "mongrel_rails cluster::#{command} -C #{conf}"
+      cmd += " --user #{user}" if user
+      cmd += " --group #{group}" if group
       cmd += " -v" if verbose
       cmd += " --clean" if clean
       puts cmd if verbose || command == "status"
@@ -30,6 +32,8 @@ OptionParser.new do |opts|
   opts.on("-c", "--conf_path PATH", "Path to mongrel_cluster configuration files") { |value| @options[:conf_path] = value }
   opts.on('-v', '--verbose', "Print all called commands and output.") { |value| @options[:verbose] = value }
   opts.on('--clean', "Remove pid files if needed beforehand.") { |value| @options[:clean] = value }
+  opts.on('--user USER', "Default user to run process as, if not specified in configuration files") { |value| @options[:user] = value }
+  opts.on('--group GROUP', "Default group to run process as, if not specified in configuration files") { |value| @options[:group] = value }
 
   if ARGV.empty?
     puts opts
@@ -52,14 +56,14 @@ end
 case @cmd[0]
 when "start": 
   puts "Starting all mongrel_clusters..."
-  run "start", @options[:verbose], @options[:clean]
+  run "start", @options[:verbose], @options[:clean], @options[:user], @options[:group]
 when "stop":
   puts "Stopping all mongrel_clusters..."
   run "stop", @options[:verbose], @options[:clean]
 when "restart":
   puts "Restarting all mongrel_clusters..."
   run "stop", @options[:verbose], @options[:clean]
-  run "start", @options[:verbose], @options[:clean]
+  run "start", @options[:verbose], @options[:clean], @options[:user], @options[:group]
 when "status":
   puts "Checking all mongrel_clusters..."
   run "status", @options[:verbose]
diff --git a/debian/mongrel-cluster.init b/debian/mongrel-cluster.init
index 8ef4ad2..349df3c 100644
--- a/debian/mongrel-cluster.init
+++ b/debian/mongrel-cluster.init
@@ -44,30 +44,34 @@ set -e
 TOTAL_CONFS=$(ls $CONF_DIR | wc -l)
 test $TOTAL_CONFS -ne 0 || exit 0
 
+# Add user and group information, if specified
+if [ ! -z "$USER" ]; then DAEMON_OPTS="$DAEMON_OPTS --user $USER"; fi
+if [ ! -z "$GROUP" ]; then DAEMON_OPTS="$DAEMON_OPTS --group $GROUP"; fi
+
 case "$1" in
   start)
 	mkdir -p $PID_DIR
         chown $USER:$GROUP $PID_DIR
 	echo -n "Starting $DESC: "
-	start-stop-daemon --start --quiet --chuid $USER:$GROUP \
+	start-stop-daemon --start --quiet \
 		--exec $DAEMON -- start $DAEMON_OPTS
 	echo "$NAME."
 	;;
   stop)
 	echo -n "Stopping $DESC: "
-	start-stop-daemon --start --quiet --chuid $USER:$GROUP \
+	start-stop-daemon --start --quiet \
 		--exec $DAEMON -- stop $DAEMON_OPTS
 	echo "$NAME."
 	;;
   restart)
 	echo -n "Restarting $DESC: "
-	start-stop-daemon --start --quiet --chuid $USER:$GROUP \
+	start-stop-daemon --start --quiet \
 		--exec $DAEMON -- restart $DAEMON_OPTS
 	echo "$NAME."
 	;;
   status)
 	echo -n "Status for $DESC: "
-	start-stop-daemon --start --quiet --chuid $USER:$GROUP \
+	start-stop-daemon --start --quiet \
 		--exec $DAEMON -- status $DAEMON_OPTS
 	;;
   # actually jus calling restart
diff --git a/lib/mongrel_cluster/init.rb b/lib/mongrel_cluster/init.rb
index 1c3a613..ee722f8 100644
--- a/lib/mongrel_cluster/init.rb
+++ b/lib/mongrel_cluster/init.rb
@@ -58,7 +58,9 @@ module Cluster
       
     def start
       read_options
-      
+      @options['user'] ||= @user
+      @options['group'] ||= @group
+
       argv = [ "mongrel_rails" ]
       argv << "start"
       argv << "-d"
@@ -230,6 +232,8 @@ module Cluster
       options [ 
         ['-C', '--config PATH', "Path to cluster configuration file", :@config_file, "config/mongrel_cluster.yml"],
         ['-v', '--verbose', "Print all called commands and output.", :@verbose, false],
+        ['-u', '--user USER',  "Default user to run process as, if not specified in configuration files", :@user, nil],
+        ['-g', '--group GROUP',  "Default group to run process as, if not specified in configuration files", :@group, nil],
         ['', '--clean', "Remove pid_file if needed before starting", :@clean, false],
         ['', '--only PORT', "Port number of cluster member", :@only, nil]
       ]
-- 
1.6.2

Attachment: signature.asc
Description: Digital signature

Reply via email to