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 opts
= 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("-D", "--daemonize", "run daemonized in the background") do |d
|
63 rackup_opts
[:daemonize] = !!d
66 opts
.on("-P", "--pid FILE", "DEPRECATED") do |f
|
67 warn
"Use of --pid/-P is strongly discouraged"
68 warn
"Use the 'pid' directive in the Rainbows!/Unicorn config file instead"
72 opts
.on("-s", "--server SERVER",
73 "this flag only exists for compatibility") do |s
|
74 warn
"-s/--server only exists for compatibility with rackup"
77 # Rainbows!/Unicorn-specific stuff
78 opts
.on("-l", "--listen {HOST:PORT|PATH}",
79 "listen on HOST:PORT or PATH",
80 "this may be specified multiple times",
81 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address
|
82 options
[:listeners] << address
85 opts
.on("-c", "--config-file FILE", "Rainbows!-specific config file") do |f
|
86 options
[:config_file] = f
89 # I'm avoiding Unicorn-specific config options on the command-line.
90 # IMNSHO, config options on the command-line are redundant given
91 # config files and make things unnecessarily complicated with multiple
92 # places to look for a config option.
94 opts
.separator
"Common options:"
96 opts
.on_tail("-h", "--help", "Show this message") do
97 puts opts
.to_s
.gsub(/^.*DEPRECATED.*$/s
, '')
101 opts
.on_tail("-v", "--version", "Show version") do
102 puts
"Rainbows! v#{Rainbows::Const::RAINBOWS_VERSION}"
109 app
= Unicorn
.builder(ARGV[0] || 'config.ru', opts
)
114 :unicorn_options => options
,
116 :daemonize => rackup_opts
[:daemonize],
120 Unicorn
::Launcher.daemonize
!(options
) if rackup_opts
[:daemonize]
121 Rainbows
.run(app
, options
)