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 195
195: def cluster?
196: @options[:only] || @options[:servers] || @options[:config]
197: end
Parse the options.
# File lib/thin/runner.rb, line 141
141: def parse!
142: parser.parse! @argv
143: @command = @argv.shift
144: @arguments = @argv
145: 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 "SSL options:"
76:
77: opts.on( "--ssl", "Enables SSL") { @options[:ssl] = true }
78: opts.on( "--ssl-key-file PATH", "Path to private key") { |path| @options[:ssl_key_file] = path }
79: opts.on( "--ssl-cert-file PATH", "Path to certificate") { |path| @options[:ssl_cert_file] = path }
80: opts.on( "--ssl-verify", "Enables SSL certificate verification") { @options[:ssl_verify] = true }
81:
82: opts.separator ""
83: opts.separator "Adapter options:"
84: opts.on("-e", "--environment ENV", "Framework environment " +
85: "(default: #{@options[:environment]})") { |env| @options[:environment] = env }
86: opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| @options[:prefix] = path }
87:
88: unless Thin.win? # Daemonizing not supported on Windows
89: opts.separator ""
90: opts.separator "Daemon options:"
91:
92: opts.on("-d", "--daemonize", "Run daemonized in the background") { @options[:daemonize] = true }
93: opts.on("-l", "--log FILE", "File to redirect output " +
94: "(default: #{@options[:log]})") { |file| @options[:log] = file }
95: opts.on("-P", "--pid FILE", "File to store PID " +
96: "(default: #{@options[:pid]})") { |file| @options[:pid] = file }
97: opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| @options[:user] = user }
98: opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| @options[:group] = group }
99: opts.on( "--tag NAME", "Additional text to display in process listing") { |tag| @options[:tag] = tag }
100:
101: opts.separator ""
102: opts.separator "Cluster options:"
103:
104: opts.on("-s", "--servers NUM", "Number of servers to start") { |num| @options[:servers] = num.to_i }
105: opts.on("-o", "--only NUM", "Send command to only one server of the cluster") { |only| @options[:only] = only.to_i }
106: opts.on("-C", "--config FILE", "Load options from config file") { |file| @options[:config] = file }
107: opts.on( "--all [DIR]", "Send command to each config files in DIR") { |dir| @options[:all] = dir } if Thin.linux?
108: opts.on("-O", "--onebyone", "Restart the cluster one by one (only works with restart command)") { @options[:onebyone] = true }
109: opts.on("-w", "--wait NUM", "Maximum wait time for server to be started in seconds (use with -O)") { |time| @options[:wait] = time.to_i }
110: end
111:
112: opts.separator ""
113: opts.separator "Tuning options:"
114:
115: opts.on("-b", "--backend CLASS", "Backend to use, full classname") { |name| @options[:backend] = name }
116: opts.on("-t", "--timeout SEC", "Request or command timeout in sec " +
117: "(default: #{@options[:timeout]})") { |sec| @options[:timeout] = sec.to_i }
118: opts.on("-f", "--force", "Force the execution of the command") { @options[:force] = true }
119: opts.on( "--max-conns NUM", "Maximum number of open file descriptors " +
120: "(default: #{@options[:max_conns]})",
121: "Might require sudo to set higher then 1024") { |num| @options[:max_conns] = num.to_i } unless Thin.win?
122: opts.on( "--max-persistent-conns NUM",
123: "Maximum number of persistent connections",
124: "(default: #{@options[:max_persistent_conns]})") { |num| @options[:max_persistent_conns] = num.to_i }
125: opts.on( "--threaded", "Call the Rack application in threads " +
126: "[experimental]") { @options[:threaded] = true }
127: opts.on( "--no-epoll", "Disable the use of epoll") { @options[:no_epoll] = true } if Thin.linux?
128:
129: opts.separator ""
130: opts.separator "Common options:"
131:
132: opts.on_tail("-r", "--require FILE", "require the library") { |file| @options[:require] << file }
133: opts.on_tail("-D", "--debug", "Set debugging on") { @options[:debug] = true }
134: opts.on_tail("-V", "--trace", "Set tracing on (log raw request/response)") { @options[:trace] = true }
135: opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
136: opts.on_tail('-v', '--version', "Show version") { puts Thin::SERVER; exit }
137: end
138: end
Parse the current shell arguments and run the command. Exits on error.
# File lib/thin/runner.rb, line 149
149: def run!
150: if self.class.commands.include?(@command)
151: run_command
152: elsif @command.nil?
153: puts "Command required"
154: puts @parser
155: exit 1
156: else
157: abort "Unknown command: #{@command}. Use one of #{self.class.commands.join(', ')}"
158: end
159: end
Send the command to the controller: single instance or cluster.
# File lib/thin/runner.rb, line 162
162: def run_command
163: load_options_from_config_file! unless CONFIGLESS_COMMANDS.include?(@command)
164:
165: # PROGRAM_NAME is relative to the current directory, so make sure
166: # we store and expand it before changing directory.
167: Command.script = File.expand_path($PROGRAM_NAME)
168:
169: # Change the current directory ASAP so that all relative paths are
170: # relative to this one.
171: Dir.chdir(@options[:chdir]) unless CONFIGLESS_COMMANDS.include?(@command)
172:
173: @options[:require].each { |r| ruby_require r }
174: Logging.debug = @options[:debug]
175: Logging.trace = @options[:trace]
176:
177: controller = case
178: when cluster? then Controllers::Cluster.new(@options)
179: when service? then Controllers::Service.new(@options)
180: else Controllers::Controller.new(@options)
181: end
182:
183: if controller.respond_to?(@command)
184: begin
185: controller.send(@command, *@arguments)
186: rescue RunnerError => e
187: abort e.message
188: end
189: else
190: abort "Invalid options for command: #{@command}"
191: end
192: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.