Object
CLI runner. Parse options and send command to the correct Controller.
Commands that wont load options from the config file
Return all available commands
# File lib/thin/runner.rb, line 24 24: def self.commands 25: commands = COMMANDS 26: commands += LINUX_ONLY_COMMANDS if Thin.linux? 27: commands 28: end
# File lib/thin/runner.rb, line 30 30: def initialize(argv) 31: @argv = argv 32: 33: # Default options values 34: @options = { 35: :chdir => Dir.pwd, 36: :environment => 'development', 37: :address => '0.0.0.0', 38: :port => Server::DEFAULT_PORT, 39: :timeout => Server::DEFAULT_TIMEOUT, 40: :log => 'log/thin.log', 41: :pid => 'tmp/pids/thin.pid', 42: :max_conns => Server::DEFAULT_MAXIMUM_CONNECTIONS, 43: :max_persistent_conns => Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS, 44: :require => [], 45: :wait => Controllers::Cluster::DEFAULT_WAIT_TIME 46: } 47: 48: parse! 49: end
true if we’re controlling a cluster.
# File lib/thin/runner.rb, line 187 187: def cluster? 188: @options[:only] || @options[:servers] || @options[:config] 189: end
Parse the options.
# File lib/thin/runner.rb, line 133 133: def parse! 134: parser.parse! @argv 135: @command = @argv.shift 136: @arguments = @argv 137: end
# File lib/thin/runner.rb, line 51 51: def parser 52: # NOTE: If you add an option here make sure the key in the +options+ hash is the 53: # same as the name of the command line option. 54: # +option+ keys are used to build the command line to launch other processes, 55: # see <tt>lib/thin/command.rb</tt>. 56: @parser ||= OptionParser.new do |opts| 57: opts.banner = "Usage: thin [options] #{self.class.commands.join('|')}" 58: 59: opts.separator "" 60: opts.separator "Server options:" 61: 62: opts.on("-a", "--address HOST", "bind to HOST address " + 63: "(default: #{@options[:address]})") { |host| @options[:address] = host } 64: opts.on("-p", "--port PORT", "use PORT (default: #{@options[:port]})") { |port| @options[:port] = port.to_i } 65: opts.on("-S", "--socket FILE", "bind to unix domain socket") { |file| @options[:socket] = file } 66: opts.on("-y", "--swiftiply [KEY]", "Run using swiftiply") { |key| @options[:swiftiply] = key } 67: opts.on("-A", "--adapter NAME", "Rack adapter to use (default: autodetect)", 68: "(#{Rack::ADAPTERS.map{|(a,b)|a}.join(', ')})") { |name| @options[:adapter] = name } 69: opts.on("-R", "--rackup FILE", "Load a Rack config file instead of " + 70: "Rack adapter") { |file| @options[:rackup] = file } 71: opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) } 72: opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| @options[:stats] = path } 73: 74: opts.separator "" 75: opts.separator "Adapter options:" 76: opts.on("-e", "--environment ENV", "Framework environment " + 77: "(default: #{@options[:environment]})") { |env| @options[:environment] = env } 78: opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| @options[:prefix] = path } 79: 80: unless Thin.win? # Daemonizing not supported on Windows 81: opts.separator "" 82: opts.separator "Daemon options:" 83: 84: opts.on("-d", "--daemonize", "Run daemonized in the background") { @options[:daemonize] = true } 85: opts.on("-l", "--log FILE", "File to redirect output " + 86: "(default: #{@options[:log]})") { |file| @options[:log] = file } 87: opts.on("-P", "--pid FILE", "File to store PID " + 88: "(default: #{@options[:pid]})") { |file| @options[:pid] = file } 89: opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| @options[:user] = user } 90: opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| @options[:group] = group } 91: opts.on( "--tag NAME", "Additional text to display in process listing") { |tag| @options[:tag] = tag } 92: 93: opts.separator "" 94: opts.separator "Cluster options:" 95: 96: opts.on("-s", "--servers NUM", "Number of servers to start") { |num| @options[:servers] = num.to_i } 97: opts.on("-o", "--only NUM", "Send command to only one server of the cluster") { |only| @options[:only] = only.to_i } 98: opts.on("-C", "--config FILE", "Load options from config file") { |file| @options[:config] = file } 99: opts.on( "--all [DIR]", "Send command to each config files in DIR") { |dir| @options[:all] = dir } if Thin.linux? 100: opts.on("-O", "--onebyone", "Restart the cluster one by one (only works with restart command)") { @options[:onebyone] = true } 101: opts.on("-w", "--wait NUM", "Maximum wait time for server to be started in seconds (use with -O)") { |time| @options[:wait] = time.to_i } 102: end 103: 104: opts.separator "" 105: opts.separator "Tuning options:" 106: 107: opts.on("-b", "--backend CLASS", "Backend to use, full classname") { |name| @options[:backend] = name } 108: opts.on("-t", "--timeout SEC", "Request or command timeout in sec " + 109: "(default: #{@options[:timeout]})") { |sec| @options[:timeout] = sec.to_i } 110: opts.on("-f", "--force", "Force the execution of the command") { @options[:force] = true } 111: opts.on( "--max-conns NUM", "Maximum number of open file descriptors " + 112: "(default: #{@options[:max_conns]})", 113: "Might require sudo to set higher then 1024") { |num| @options[:max_conns] = num.to_i } unless Thin.win? 114: opts.on( "--max-persistent-conns NUM", 115: "Maximum number of persistent connections", 116: "(default: #{@options[:max_persistent_conns]})") { |num| @options[:max_persistent_conns] = num.to_i } 117: opts.on( "--threaded", "Call the Rack application in threads " + 118: "[experimental]") { @options[:threaded] = true } 119: opts.on( "--no-epoll", "Disable the use of epoll") { @options[:no_epoll] = true } if Thin.linux? 120: 121: opts.separator "" 122: opts.separator "Common options:" 123: 124: opts.on_tail("-r", "--require FILE", "require the library") { |file| @options[:require] << file } 125: opts.on_tail("-D", "--debug", "Set debbuging on") { @options[:debug] = true } 126: opts.on_tail("-V", "--trace", "Set tracing on (log raw request/response)") { @options[:trace] = true } 127: opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } 128: opts.on_tail('-v', '--version', "Show version") { puts Thin::SERVER; exit } 129: end 130: end
Parse the current shell arguments and run the command. Exits on error.
# File lib/thin/runner.rb, line 141 141: def run! 142: if self.class.commands.include?(@command) 143: run_command 144: elsif @command.nil? 145: puts "Command required" 146: puts @parser 147: exit 1 148: else 149: abort "Unknown command: #{@command}. Use one of #{self.class.commands.join(', ')}" 150: end 151: end
Send the command to the controller: single instance or cluster.
# File lib/thin/runner.rb, line 154 154: def run_command 155: load_options_from_config_file! unless CONFIGLESS_COMMANDS.include?(@command) 156: 157: # PROGRAM_NAME is relative to the current directory, so make sure 158: # we store and expand it before changing directory. 159: Command.script = File.expand_path($PROGRAM_NAME) 160: 161: # Change the current directory ASAP so that all relative paths are 162: # relative to this one. 163: Dir.chdir(@options[:chdir]) unless CONFIGLESS_COMMANDS.include?(@command) 164: 165: @options[:require].each { |r| ruby_require r } 166: Logging.debug = @options[:debug] 167: Logging.trace = @options[:trace] 168: 169: controller = case 170: when cluster? then Controllers::Cluster.new(@options) 171: when service? then Controllers::Service.new(@options) 172: else Controllers::Controller.new(@options) 173: end 174: 175: if controller.respond_to?(@command) 176: begin 177: controller.send(@command, *@arguments) 178: rescue RunnerError => e 179: abort e.message 180: end 181: else 182: abort "Invalid options for command: #{@command}" 183: end 184: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.