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