Description: Allows Mongrel instances to be run under different users, 
 specified in configuration file
Origin: vendor
Bug-Debian: http://bugs.debian.org/500424
Author: Gunnar Wolf <gwolf@debian.org>
Forwarded: http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=10;bug=500424
Last-Update: 2010-02-18

diff --git a/bin/mongrel_cluster_ctl b/bin/mongrel_cluster_ctl
--- 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/lib/mongrel_cluster/init.rb b/lib/mongrel_cluster/init.rb
--- 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

