1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/bin/env ruby
# Copyright (c) 2006 Bradley Taylor, bradley@fluxura.com
require 'optparse'
def run(command, verbose, clean=false)
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 += " -v" if verbose
cmd += " --clean" if clean
puts cmd if verbose || command == "status"
output = `#{cmd}`
puts output if verbose || command == "status"
puts "mongrel_rails cluster::#{command} returned an error." unless $?.success?
end
end
end
@options = {}
@options[:conf_path] = "/etc/mongrel_cluster"
@options[:verbose] = false
@options[:clean] = false
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} (start|stop|restart|status) [options]"
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 }
if ARGV.empty?
puts opts
exit
else
@cmd = opts.parse!(ARGV)
if @cmd.nil?
puts opts
exit
end
end
end
if @options[:conf_path] == nil && !File.directory?(@options[:conf_path])
puts "Invalid path to mongrel_cluster configuration files: #{@options[:conf_path]}"
exit
end
case @cmd[0]
when "start":
puts "Starting all mongrel_clusters..."
run "start", @options[:verbose], @options[:clean]
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]
when "status":
puts "Checking all mongrel_clusters..."
run "status", @options[:verbose]
else
puts "Unknown command."
end
exit
|