0
-#
<tt>thin start</tt>: Starts the Rails app in the current directory.
0
+#
Thin command line interface script.
0
# Run <tt>thin -h</tt> to get more usage.
0
require File.dirname(__FILE__) + '/../lib/thin'
0
-COMMANDS = %w(start stop restart config)
0
-# Default options values
0
- :environment => 'development',
0
- :address => '0.0.0.0',
0
- :log => 'log/thin.log',
0
- :pid => 'tmp/pids/thin.pid',
0
- :servers => 1 # no cluster
0
-# NOTE: If you add an option here make sure the key in the +options+ hash is the
0
-# same as the name of the command line option.
0
-# +option+ keys are use to build the command line to launch a cluster,
0
-# see <tt>lib/thin/cluster.rb</tt>.
0
-opts = OptionParser.new do |opts|
0
- opts.banner = "Usage: thin [options] #{COMMANDS.join('|')}"
0
- opts.separator "Server options:"
0
- opts.on("-a", "--address HOST", "bind to HOST address (default: 0.0.0.0)") { |host| options[:address] = host }
0
- opts.on("-p", "--port PORT", "use PORT (default: 3000)") { |port| options[:port] = port.to_i }
0
- opts.on("-S", "--socket PATH", "bind to unix domain socket") { |file| options[:socket] = file }
0
- opts.on("-e", "--environment ENV", "Rails environment (default: development)") { |env| options[:environment] = env }
0
- opts.on("-c", "--chdir PATH", "Change to dir before starting") { |dir| options[:chdir] = File.expand_path(dir) }
0
- opts.on("-t", "--timeout SEC", "Request or command timeout in sec",
0
- "(default: #{options[:timeout]})") { |sec| options[:timeout] = sec.to_i }
0
- opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| options[:prefix] = path }
0
- opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| options[:stats] = path }
0
- opts.separator "Daemon options:"
0
- opts.on("-d", "--daemonize", "Run daemonized in the background") { options[:daemonize] = true }
0
- opts.on("-l", "--log FILE", "File to redirect output",
0
- "(default: #{options[:log]})") { |file| options[:log] = file }
0
- opts.on("-P", "--pid FILE", "File to store PID",
0
- "(default: #{options[:pid]})") { |file| options[:pid] = file }
0
- opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
0
- opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
0
- opts.separator "Cluster options:"
0
- opts.on("-s", "--servers NUM", "Number of servers to start",
0
- "set a value >1 to start a cluster") { |num| options[:servers] = num.to_i }
0
- opts.on("-o", "--only NUM", "Send command to only one server of the cluster") { |only| options[:only] = only }
0
- opts.on("-C", "--config PATH", "Load options from a config file") { |file| options[:config] = file }
0
- opts.separator "Common options:"
0
- opts.on_tail("-D", "--debug", "Set debbuging on") { $DEBUG = true }
0
- opts.on_tail("-V", "--trace", "Set tracing on") { $TRACE = true }
0
- opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
0
- opts.on_tail('-v', '--version', "Show version") { puts Thin::SERVER; exit }
0
- options[:only] || (options[:servers] && options[:servers] > 1)
0
-def load_options_from_config_file!(options)
0
- if file = options.delete(:config)
0
- YAML.load_file(file).each { |key, value| options[key.to_sym] = value }
0
-# == Commands definitions
0
- load_options_from_config_file! options
0
- Thin::Cluster.new(options).start
0
- server = Thin::Server.new(options[:socket])
0
- server = Thin::Server.new(options[:address], options[:port])
0
- server.pid_file = options[:pid]
0
- server.log_file = options[:log]
0
- server.timeout = options[:timeout]
0
- if options[:daemonize]
0
- server.change_privilege options[:user], options[:group] if options[:user] && options[:group]
0
- server.app = Rack::Adapter::Rails.new(options.merge(:root => options[:chdir]))
0
- # If a prefix is required, wrap in Rack URL mapper
0
- server.app = Rack::URLMap.new(options[:prefix] => server.app) if options[:prefix]
0
- # If a stats are required, wrap in Stats adapter
0
- server.app = Thin::Stats::Adapter.new(server.app, options[:stats]) if options[:stats]
0
- load_options_from_config_file! options
0
- Thin::Cluster.new(options).stop
0
- Thin::Server.kill options[:pid], options[:timeout]
0
- load_options_from_config_file! options
0
- Thin::Cluster.new(options).restart
0
- # Restart only make sense when running as a daemon
0
- options.update :daemonize => true
0
- config_file = options.delete(:config) || abort('config option required')
0
- options.keys.each { |o| options[o.to_s] = options.delete(o) }
0
- File.open(config_file, 'w') { |f| f << options.to_yaml }
0
- puts "Wrote configuration to #{config_file}"
0
-Dir.chdir(options[:chdir])
0
-if COMMANDS.include?(command)
0
- send(command, options)
0
- puts "Command required"
0
- abort "Invalid command : #{command}"
0
+Thin::Runner.new(ARGV).run!