lib/mongrel_cluster/init.rb in mongrel_cluster-0.1 vs lib/mongrel_cluster/init.rb in mongrel_cluster-0.1.1
- old
+ new
@@ -6,24 +6,21 @@
class Start < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
def configure
- options [['-C', '--config PATH', "Path to configuraion file", :@config_file, "config/mongrel_cluster.yml"]]
+ options [['-C', '--config PATH', "Path to configuration file", :@config_file, "config/mongrel_cluster.yml"]]
end
def validate
valid_exists?(@config_file, "Configuration file does not exist. Run mongrel_rails cluster::configure.")
return @valid
end
def run
@options = {
- "environment" => ENV['RAILS_ENV'] || "development",
"port" => 3000,
- "address" => "0.0.0.0",
- "log_file" => "log/mongrel.log",
"pid_file" => "log/mongrel.pid",
"servers" => 2
}
@conf_options = YAML.load_file(@config_file)
@@ -33,20 +30,20 @@
puts "Starting #{@options["servers"]} Mongrel servers..."
1.upto(@options["servers"].to_i) do |i|
argv = [ "mongrel_rails" ]
argv << "start"
argv << "-d"
- argv << "-e #{@options["environment"]}"
+ argv << "-e #{@options["environment"]}" if @options["environment"]
argv << "-p #{port+i}"
- argv << "-a #{@options["address"]}"
- argv << "-l #{@options["log_file"]}"
- argv << "-P #{pid[0]}-#{i}.#{pid[1]}"
- argv << "-c #{@options["cwd"]}"
- argv << "-t #{@options["timeout"]}"
+ argv << "-a #{@options["address"]}" if @options["address"]
+ argv << "-l #{@options["log_file"]}" if @options["log_file"]
+ argv << "-P #{pid[0]}.#{port+i}.#{pid[1]}"
+ argv << "-c #{@options["cwd"]}" if @options["cwd"]
+ argv << "-t #{@options["timeout"]}" if @options["timeout"]
argv << "-m #{@options["mime_map"]}" if @options["mime_map"]
- argv << "-r #{@options["docroot"]}"
- argv << "-n #{@options["num-procs"]}"
+ 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"]
cmd = argv.join " "
puts cmd
status = `#{cmd}`
@@ -72,22 +69,26 @@
def run
@options = {
"environment" => ENV['RAILS_ENV'] || "development",
"port" => 3000,
- "address" => "0.0.0.0",
- "log_file" => "log/mongrel.log",
"pid_file" => "log/mongrel.pid",
"servers" => 2
}
@conf_options = YAML.load_file(@config_file)
@options.merge! @conf_options if @conf_options
+ port = @options["port"].to_i - 1
pid = @options["pid_file"].split(".")
puts "Stopping #{@options["servers"]} Mongrel servers..."
1.upto(@options["servers"].to_i) do |i|
- cmd = "mongrel_rails stop -P #{pid[0]}-#{i}.#{pid[1]} -c #{@options["cwd"]} #{"-f" if @force }"
+ argv = [ "mongrel_rails" ]
+ 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
end
end
@@ -108,24 +109,27 @@
return @valid
end
def run
@options = {
- "environment" => ENV['RAILS_ENV'] || "development",
"port" => 3000,
- "address" => "0.0.0.0",
- "log_file" => "log/mongrel.log",
"pid_file" => "log/mongrel.pid",
"servers" => 2
}
@conf_options = YAML.load_file(@config_file)
@options.merge! @conf_options if @conf_options
+ port = @options["port"].to_i - 1
pid = @options["pid_file"].split(".")
puts "Restarting #{@options["servers"]} Mongrel servers..."
1.upto(@options["servers"].to_i) do |i|
- cmd = "mongrel_rails restart -P #{pid[0]}-#{i}.#{pid[1]} -c #{@options["cwd"]} #{"-s" if @soft }"
+ argv = [ "mongrel_rails" ]
+ 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
end
end
@@ -134,64 +138,55 @@
class Configure < GemPlugin::Plugin "/commands"
include Mongrel::Command::Base
def configure
options [
- ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
+ ["-e", "--environment ENV", "Rails environment to run as", :@environment, nil],
['-p', '--port PORT', "Starting port to bind to", :@port, 3000],
- ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
- ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
+ ['-a', '--address ADDR', "Address to bind to", :@address, nil],
+ ['-l', '--log FILE', "Where to write log messages", :@log_file, nil],
['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
- ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
- ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, 120],
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, nil],
+ ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, nil],
['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
- ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
- ['-n', '--num-procs INT', "Number of processor threads to use", :@num_procs, 1024],
- ['-B', '--debug', "Enable debugging mode", :@debug, false],
+ ['-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"]
]
end
def validate
@servers = @servers.to_i
- @port = @port.to_i
- @timeout = @timeout.to_i
- @cwd = File.expand_path(@cwd)
- valid_dir? @cwd, "Invalid path to change to during daemon mode: #{@cwd}"
valid?(@servers > 0, "Must give a valid number of servers")
- valid?(@port > 0, "Must give a valid starting port")
- valid?(@timeout > 0, "Must give a valid timeout for requests")
-
- valid_dir? File.dirname(@log_file), "Path to log file not valid: #{@log_file}"
- valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #{@pid_file}"
valid_dir? File.dirname(@config_file), "Path to config file not valid: #{@config_file}"
- valid_dir? File.dirname(@docroot), "Path to docroot not valid: #{@docroot}"
- valid_exists? @mime_map, "MIME mapping file does not exist: #{@mime_map}" if @mime_map
-
return @valid
end
def run
@options = {
- "environment" => @environment,
"port" => @port,
- "address" => @address,
- "log_file" => @log_file,
- "pid_file" => @pid_file,
"servers" => @servers,
- "cwd" => @cwd,
- "timeout" => @timeout,
- "mime_map" => @mime_map,
- "docroot" => @docroot,
- "debug" => @debug,
- "config_script" => @config_script,
- "num-procs" => @num_procs
+ "pid_file" => @pid_file
}
+
+ @options["log_file"] = @log_file if @log_file
+ @options["debug"] = @debug if @debug
+ @options["num_procs"] = @num_procs if @num_procs
+ @options["docroot"] = @docroot if @docroots
+ @options["address"] = @address if @address
+ @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
+
puts "Writing configuration file to #{@config_file}."
File.open(@config_file,"w") {|f| f.write(@options.to_yaml)}
end
end
-end
\ No newline at end of file
+end
+