tests: bump tests to use rack 1.4.3
[unicorn.git] / bin / unicorn
blob9962b58eb0607c7db6cc2666ad49f35ffdeddfea
1 #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2 # -*- encoding: binary -*-
3 require 'unicorn/launcher'
4 require 'optparse'
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:"
16 lineno = 1
17 opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
18 eval line, TOPLEVEL_BINDING, "-e", lineno
19 lineno += 1
20 end
22 opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
23 $DEBUG = true
24 end
26 opts.on("-w", "--warn", "turn warnings on for your script") do
27 $-w = true
28 end
30 opts.on("-I", "--include PATH",
31 "specify $LOAD_PATH (may be used more than once)") do |path|
32 $LOAD_PATH.unshift(*path.split(/:/))
33 end
35 opts.on("-r", "--require LIBRARY",
36 "require the library, before executing your script") do |library|
37 require library
38 end
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
48 end
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
54 end
56 opts.on("-E", "--env RACK_ENV",
57 "use RACK_ENV for defaults (default: development)") do |e|
58 ENV["RACK_ENV"] = e
59 end
61 opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
62 rackup_opts[:daemonize] = !!d
63 end
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}
68 options[:pid] = f
69 end
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"
74 end
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
82 end
84 opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
85 options[:config_file] = f
86 end
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, '')
97 exit
98 end
100 opts.on_tail("-v", "--version", "Show version") do
101 puts "#{cmd} v#{Unicorn::Const::UNICORN_VERSION}"
102 exit
105 opts.parse! ARGV
108 app = Unicorn.builder(ARGV[0] || 'config.ru', op)
109 op = nil
111 if $DEBUG
112 require 'pp'
113 pp({
114 :unicorn_options => options,
115 :app => app,
116 :daemonize => rackup_opts[:daemonize],
120 Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
121 Unicorn::HttpServer.new(app, options).start.join