Skip to content

Instantly share code, notes, and snippets.

@filterfish
Created January 28, 2010 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filterfish/288321 to your computer and use it in GitHub Desktop.
Save filterfish/288321 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Copyright (c) 2006 Bradley Taylor, bradley@fluxura.com
# Modified by Richard Heycock to support thin. rgh@roughage.com.au
require 'optparse'
def run(command, verbose, clean=false)
bin = 'thin'
opts = "--all #{@options[:conf_path]}"
opts += " --clean" if clean
opts += " --onebyone" if command == 'restart'
cmd = "#{bin} #{opts} #{command}"
puts cmd if verbose
output = `#{cmd}`
puts output if verbose
puts "#{cmd} returned an error." unless $?.success?
end
@options = {}
@options[:conf_path] = "/etc/thin_cluster"
@options[:verbose] = false
@options[:clean] = false
commands = 'start|stop|restart'
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] (#{commands})"
opts.on("-c", "--conf_path PATH", "Path to thin configuration files (default: #{@options[:conf_path]})") { |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 thin configuration files: #{@options[:conf_path]}"
exit
end
unless Regexp.new(commands).match(@cmd[0])
puts "Unknown command. Valid commands: #{commands}"
exit
end
puts "#{@cmd[0].capitalize}ing all thin clusters ..."
run @cmd[0], @options[:verbose], @options[:clean]
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment