1 #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2 # -*- encoding: binary -*-
3 require 'unicorn/launcher'
7 ENV["RACK_ENV"] ||= "development"
8 rackup_opts
= Unicorn
::Configurator::RACKUP
9 options
= rackup_opts
[:options]
11 op
= OptionParser
.new("", 24, ' ') do |opts
|
12 cmd
= File
.basename($0)
13 opts
.banner
= "Usage: #{cmd} " \
14 "[ruby options] [#{cmd} options] [rackup config file]"
15 opts
.separator
"Ruby options:"
18 opts
.on("-e", "--eval LINE", "evaluate a LINE of code") do |line
|
19 eval line
, TOPLEVEL_BINDING
, "-e", lineno
23 opts
.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
27 opts
.on("-w", "--warn", "turn warnings on for your script") do
31 opts
.on("-I", "--include PATH",
32 "specify $LOAD_PATH (may be used more than once)") do |path
|
33 $LOAD_PATH.unshift(*path
.split(/:/))
36 opts
.on("-r", "--require LIBRARY",
37 "require the library, before executing your script") do |library
|
41 opts
.separator
"#{cmd} options:"
43 # some of these switches exist for rackup command-line compatibility,
45 opts
.on("-o", "--host HOST",
46 "listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h
|
47 rackup_opts
[:host] = h
48 rackup_opts
[:set_listener] = true
51 opts
.on("-p", "--port PORT",
52 "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p
|
53 rackup_opts
[:port] = p
.to_i
54 rackup_opts
[:set_listener] = true
57 opts
.on("-E", "--env RACK_ENV",
58 "use RACK_ENV for defaults (default: development)") do |e
|
62 opts
.on("-N", "--no-default-middleware",
63 "do not load middleware implied by RACK_ENV") do |e
|
64 rackup_opts
[:no_default_middleware] = true
67 opts
.on("-D", "--daemonize", "run daemonized in the background") do |d
|
68 rackup_opts
[:daemonize] = !!d
71 opts
.on("-P", "--pid FILE", "DEPRECATED") do |f
|
72 warn
"Use of --pid/-P is strongly discouraged"
73 warn
"Use the 'pid' directive in the Rainbows!/Unicorn config file instead"
77 opts
.on("-s", "--server SERVER",
78 "this flag only exists for compatibility") do |s
|
79 warn
"-s/--server only exists for compatibility with rackup"
82 # Rainbows!/Unicorn-specific stuff
83 opts
.on("-l", "--listen {HOST:PORT|PATH}",
84 "listen on HOST:PORT or PATH",
85 "this may be specified multiple times",
86 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address
|
87 options
[:listeners] << address
90 opts
.on("-c", "--config-file FILE", "Rainbows!-specific config file") do |f
|
91 options
[:config_file] = f
94 # I'm avoiding Unicorn-specific config options on the command-line.
95 # IMNSHO, config options on the command-line are redundant given
96 # config files and make things unnecessarily complicated with multiple
97 # places to look for a config option.
99 opts
.separator
"Common options:"
101 opts
.on_tail("-h", "--help", "Show this message") do
102 puts opts
.to_s
.gsub(/^.*DEPRECATED.*$/s
, '')
106 opts
.on_tail("-v", "--version", "Show version") do
107 puts
"Rainbows! v#{Rainbows::Const::RAINBOWS_VERSION}"
114 app
= Unicorn
.builder(ARGV[0] || 'config.ru', op
)
120 :unicorn_options => options
,
122 :daemonize => rackup_opts
[:daemonize],
126 Unicorn
::Launcher.daemonize
!(options
) if rackup_opts
[:daemonize]
127 Rainbows
::HttpServer.new(app
, options
).start
.join