Created
January 28, 2010 00:55
-
-
Save filterfish/288321 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Copyright (c) 2006 Bradley Taylor, [email protected] | |
# Modified by Richard Heycock to support thin. [email protected] | |
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