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 opts
= 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",
51 "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p
|
52 rackup_opts
[:port] = p
.to_i
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("-D", "--daemonize", "run daemonized in the background") do |d
|
62 rackup_opts
[:daemonize] = !!d
65 opts
.on("-P", "--pid FILE", "DEPRECATED") do |f
|
66 warn
%q{Use of --pid/-P is strongly discouraged}
67 warn %q{Use the 'pid' directive in the Unicorn config file instead}
71 opts.on("-s", "--server SERVER",
72 "this flag only exists for compatibility") do |s|
73 warn "-s/--server only exists for compatibility with rackup"
76 # Unicorn-specific stuff
77 opts.on("-l", "--listen {HOST:PORT|PATH}",
78 "listen on HOST:PORT or PATH",
79 "this may be specified multiple times",
80 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
81 options[:listeners] << address
84 opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
85 options[:config_file] = f
88 # I'm avoiding Unicorn-specific config options on the command-line.
89 # IMNSHO, config options on the command-line are redundant given
90 # config files and make things unnecessarily complicated with multiple
91 # places to look for a config option.
93 opts.separator "Common options:"
95 opts.on_tail("-h", "--help", "Show this message") do
96 puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
100 opts.on_tail("-v", "--version", "Show version") do
101 puts "#{cmd} v#{Unicorn::Const::UNICORN_VERSION}"
108 app = Unicorn.builder(ARGV[0] || 'config.ru', opts)
113 :unicorn_options => options,
115 :daemonize => rackup_opts[:daemonize],
119 Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
120 Unicorn.run(app, options)