1 #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2 # -*- encoding: binary -*-
3 require 'unicorn/launcher'
6 ENV["RACK_ENV"] ||= "development"
8 options
= { :listeners => [] }
9 host
, port
= Unicorn
::Const::DEFAULT_HOST, Unicorn
::Const::DEFAULT_PORT
12 opts
= OptionParser
.new("", 24, ' ') do |opts
|
13 cmd
= File
.basename($0)
14 opts
.banner
= "Usage: #{cmd} " \
15 "[ruby options] [#{cmd} options] [rackup config file]"
17 opts
.separator
"Ruby options:"
20 opts
.on("-e", "--eval LINE", "evaluate a LINE of code") do |line
|
21 eval line
, TOPLEVEL_BINDING
, "-e", lineno
25 opts
.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
29 opts
.on("-w", "--warn", "turn warnings on for your script") do
33 opts
.on("-I", "--include PATH",
34 "specify $LOAD_PATH (may be used more than once)") do |path
|
35 $LOAD_PATH.unshift(*path
.split(/:/))
38 opts
.on("-r", "--require LIBRARY",
39 "require the library, before executing your script") do |library
|
43 opts
.separator
"#{cmd} options:"
45 # some of these switches exist for rackup command-line compatibility,
47 opts
.on("-o", "--host HOST",
48 "listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h
|
53 opts
.on("-p", "--port PORT",
54 "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p
|
59 opts
.on("-E", "--env ENVIRONMENT",
60 "use ENVIRONMENT for defaults (default: development)") do |e
|
64 opts
.on("-D", "--daemonize", "run daemonized in the background") do |d
|
65 daemonize
= d
? true : false
68 opts
.on("-P", "--pid FILE", "DEPRECATED") do |f
|
69 warn
%q{Use of --pid/-P is strongly discouraged}
70 warn %q{Use the 'pid' directive in the Unicorn config file instead}
74 opts.on("-s", "--server SERVER",
75 "this flag only exists for compatibility") do |s|
76 warn "-s/--server only exists for compatibility with rackup"
79 # Unicorn-specific stuff
80 opts.on("-l", "--listen {HOST:PORT|PATH}",
81 "listen on HOST:PORT or PATH",
82 "this may be specified multiple times",
83 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
84 options[:listeners] << address
87 opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
88 options[:config_file] = f
91 # I'm avoiding Unicorn-specific config options on the command-line.
92 # IMNSHO, config options on the command-line are redundant given
93 # config files and make things unnecessarily complicated with multiple
94 # places to look for a config option.
96 opts.separator "Common options:"
98 opts.on_tail("-h", "--help", "Show this message") do
99 puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
103 opts.on_tail("-v", "--version", "Show version") do
104 puts "#{cmd} v#{Unicorn::Const::UNICORN_VERSION}"
111 app = Unicorn.builder(ARGV[0] || 'config.ru', opts)
112 options[:listeners] << "#{host}:#{port}" if set_listener
117 :unicorn_options => options,
119 :daemonize => daemonize,
123 Unicorn::Launcher.daemonize!(options) if daemonize
124 Unicorn.run(app, options)