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