lib/mongrel_cluster/init.rb in mongrel_cluster-0.1.1 vs lib/mongrel_cluster/init.rb in mongrel_cluster-0.2.0
- old
+ new
@@ -6,11 +6,14 @@
class Start < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
def configure
- options [['-C', '--config PATH', "Path to configuration file", :@config_file, "config/mongrel_cluster.yml"]]
+ options [
+ ['-C', '--config PATH', "Path to configuration file", :@config_file, "config/mongrel_cluster.yml"],
+ ['-v', '--verbose', "Print all called commands and output.", :@verbose, false]
+ ]
end
def validate
valid_exists?(@config_file, "Configuration file does not exist. Run mongrel_rails cluster::configure.")
return @valid
@@ -42,25 +45,32 @@
argv << "-m #{@options["mime_map"]}" if @options["mime_map"]
argv << "-r #{@options["docroot"]}" if @options["docroot"]
argv << "-n #{@options["num_procs"]}" if @options["num_procs"]
argv << "-B" if @options["debug"]
argv << "-S #{@options["config_script"]}" if @options["config_script"]
+ argv << "--user #{@options["user"]}" if @options["user"]
+ argv << "--group #{@options["group"]}" if @options["group"]
cmd = argv.join " "
- puts cmd
- status = `#{cmd}`
- puts status
+
+ puts cmd if @verbose
+ output = `#{cmd}`
+ unless $?.success?
+ puts cmd unless @verbose
+ puts output
+ end
end
end
end
class Stop < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
def configure
options [
['-C', '--config PATH', "Path to config file", :@config_file, "config/mongrel_cluster.yml"],
- ['-f', '--force', "Force the shutdown.", :@force, false]
+ ['-f', '--force', "Force the shutdown.", :@force, false],
+ ['-v', '--verbose', "Print all called commands and output.", :@verbose, false]
]
end
def validate
valid_exists?(@config_file, "Configuration file does not exist. Run mongrel_rails cluster::configure.")
@@ -85,24 +95,28 @@
argv << "stop"
argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
argv << "-c #{@options["cwd"]}" if @options["cwd"]
argv << "-f" if @force
cmd = argv.join " "
- puts cmd
- status = `#{cmd}`
- puts status
+ puts cmd if @verbose
+ output = `#{cmd}`
+ unless $?.success?
+ puts cmd unless @verbose
+ puts output
+ end
end
end
end
class Restart < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
def configure
options [
['-C', '--config PATH', "Path to config file", :@config_file, "config/mongrel_cluster.yml"],
- ['-s', '--soft', "Do a soft restart rather than a process exit restart", :@soft, false]
+ ['-s', '--soft', "Do a soft restart rather than a process exit restart", :@soft, false],
+ ['-v', '--verbose', "Print all called commands and output.", :@verbose, false]
]
end
def validate
valid_exists?(@config_file, "Configuration file does not exist. Run mongrel_rails cluster::configure.")
@@ -126,13 +140,16 @@
argv << "restart"
argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
argv << "-c #{@options["cwd"]}" if @options["cwd"]
argv << "-s" if @soft
cmd = argv.join " "
- puts cmd
- status = `#{cmd}`
- puts status
+ puts cmd if @verbose
+ output = `#{cmd}`
+ unless $?.success?
+ puts cmd unless @verbose
+ puts output
+ end
end
end
end
class Configure < GemPlugin::Plugin "/commands"
@@ -151,11 +168,13 @@
['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, nil],
['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, nil],
['-B', '--debug', "Enable debugging mode", :@debug, nil],
['-S', '--script PATH', "Load the given file as an extra config script.", :@config_script, nil],
['-N', '--num-servers INT', "Number of Mongrel servers", :@servers, 2],
- ['-C', '--config PATH', "Path to config file", :@config_file, "config/mongrel_cluster.yml"]
+ ['-C', '--config PATH', "Path to config file", :@config_file, "config/mongrel_cluster.yml"],
+ ['', '--user USER', "User to run as", :@user, nil],
+ ['', '--group GROUP', "Group to run as", :@group, nil]
]
end
def validate
@servers = @servers.to_i
@@ -181,9 +200,11 @@
@options["timeout"] = @timeout if @timeout
@options["environment"] = @environment if @environment
@options["mime_map"] = @mime_map if @mime_map
@options["config_script"] = @config_script if @config_script
@options["cwd"] = @cwd if @cwd
+ @options["user"] = @user if @user
+ @options["group"] = @group if @group
puts "Writing configuration file to #{@config_file}."
File.open(@config_file,"w") {|f| f.write(@options.to_yaml)}
end
end