Add -N or --no-default-middleware option.
[rainbows.git] / bin / rainbows
blobf5ddaa7e091c97be9780c705387539007a4cbbc9
1 #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2 # -*- encoding: binary -*-
3 require 'unicorn/launcher'
4 require 'rainbows'
5 require 'optparse'
7 ENV["RACK_ENV"] ||= "development"
8 rackup_opts = Unicorn::Configurator::RACKUP
9 options = rackup_opts[:options]
11 op = 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:"
17 lineno = 1
18 opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
19 eval line, TOPLEVEL_BINDING, "-e", lineno
20 lineno += 1
21 end
23 opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
24 $DEBUG = true
25 end
27 opts.on("-w", "--warn", "turn warnings on for your script") do
28 $-w = true
29 end
31 opts.on("-I", "--include PATH",
32 "specify $LOAD_PATH (may be used more than once)") do |path|
33 $LOAD_PATH.unshift(*path.split(/:/))
34 end
36 opts.on("-r", "--require LIBRARY",
37 "require the library, before executing your script") do |library|
38 require library
39 end
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
49 end
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
55 end
57 opts.on("-E", "--env RACK_ENV",
58 "use RACK_ENV for defaults (default: development)") do |e|
59 ENV["RACK_ENV"] = e
60 end
62 opts.on("-N", "--no-default-middleware",
63 "do not load middleware implied by RACK_ENV") do |e|
64 rackup_opts[:no_default_middleware] = true
65 end
67 opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
68 rackup_opts[:daemonize] = !!d
69 end
71 opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
72 warn "Use of --pid/-P is strongly discouraged"
73 warn "Use the 'pid' directive in the Rainbows!/Unicorn config file instead"
74 options[:pid] = f
75 end
77 opts.on("-s", "--server SERVER",
78 "this flag only exists for compatibility") do |s|
79 warn "-s/--server only exists for compatibility with rackup"
80 end
82 # Rainbows!/Unicorn-specific stuff
83 opts.on("-l", "--listen {HOST:PORT|PATH}",
84 "listen on HOST:PORT or PATH",
85 "this may be specified multiple times",
86 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
87 options[:listeners] << address
88 end
90 opts.on("-c", "--config-file FILE", "Rainbows!-specific config file") do |f|
91 options[:config_file] = f
92 end
94 # I'm avoiding Unicorn-specific config options on the command-line.
95 # IMNSHO, config options on the command-line are redundant given
96 # config files and make things unnecessarily complicated with multiple
97 # places to look for a config option.
99 opts.separator "Common options:"
101 opts.on_tail("-h", "--help", "Show this message") do
102 puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
103 exit
106 opts.on_tail("-v", "--version", "Show version") do
107 puts "Rainbows! v#{Rainbows::Const::RAINBOWS_VERSION}"
108 exit
111 opts.parse! ARGV
114 app = Unicorn.builder(ARGV[0] || 'config.ru', op)
115 op = nil
117 if $DEBUG
118 require 'pp'
119 pp({
120 :unicorn_options => options,
121 :app => app,
122 :daemonize => rackup_opts[:daemonize],
126 Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
127 Rainbows::HttpServer.new(app, options).start.join