Sha256: f1755abf29d07378db91c2fb1d60d6fd5925879ed7bf2824fe5d2e5ebb9b0016

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
# Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com

require 'optparse'

def run(command, verbose)
  Dir.chdir @options[:conf_path] do 
    Dir.glob("*.yml").each do |config|
      cmd = "mongrel_rails cluster::#{command} -c #{config}"
      cmd += " -v" if verbose
      puts cmd if verbose
      output = `#{cmd}`
      puts output if verbose
      puts "mongrel_rails cluster::#{command} returned an error." unless $?.success?     
    end
  end  
end

@options = {}
@options[:conf_path] = "/etc/mongrel_cluster"
@options[:verbose] = false

OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} (start|stop|restart) [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 }

  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]
when "stop":
  puts "Stopping all mongrel_clusters..."
  run "stop", @options[:verbose]
when "restart":
  puts "Restarting all mongrel_clusters..."
  run "stop", @options[:verbose]
  run "start", @options[:verbose]
else
 puts "Unknown command."
end

exit

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongrel_cluster-0.2.0 bin/mongrel_cluster_ctl