rev + em: enable keepalive for pipe/socket responses
[rainbows.git] / bin / rainbows
blob685dd09425f2a296bdca6417177b795d794d9e7e
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 daemonize = false
9 listeners = []
10 options = { :listeners => listeners }
11 host, port = Unicorn::Const::DEFAULT_HOST, Unicorn::Const::DEFAULT_PORT
12 set_listener = false
14 opts = OptionParser.new("", 24, ' ') do |opts|
15 opts.banner = "Usage: #{File.basename($0)} " \
16 "[ruby options] [unicorn options] [rackup config file]"
18 opts.separator "Ruby options:"
20 lineno = 1
21 opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
22 eval line, TOPLEVEL_BINDING, "-e", lineno
23 lineno += 1
24 end
26 opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
27 $DEBUG = true
28 end
30 opts.on("-w", "--warn", "turn warnings on for your script") do
31 $-w = true
32 end
34 opts.on("-I", "--include PATH",
35 "specify $LOAD_PATH (may be used more than once)") do |path|
36 $LOAD_PATH.unshift(*path.split(/:/))
37 end
39 opts.on("-r", "--require LIBRARY",
40 "require the library, before executing your script") do |library|
41 require library
42 end
44 opts.separator "Rainbows!/Unicorn options:"
46 # some of these switches exist for rackup command-line compatibility,
48 opts.on("-o", "--host HOST",
49 "listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h|
50 host = h
51 set_listener = true
52 end
54 opts.on("-p", "--port PORT",
55 "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p|
56 port = p.to_i
57 set_listener = true
58 end
60 opts.on("-E", "--env RACK_ENV",
61 "use RACK_ENV for defaults (default: development)") do |e|
62 ENV["RACK_ENV"] = e
63 end
65 opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
66 daemonize = d ? true : false
67 end
69 opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
70 warn "Use of --pid/-P is strongly discouraged"
71 warn "Use the 'pid' directive in the Rainbows!/Unicorn config file instead"
72 options[:pid] = f
73 end
75 opts.on("-s", "--server SERVER",
76 "this flag only exists for compatibility") do |s|
77 warn "-s/--server only exists for compatibility with rackup"
78 end
80 # Rainbows!/Unicorn-specific stuff
81 opts.on("-l", "--listen {HOST:PORT|PATH}",
82 "listen on HOST:PORT or PATH",
83 "this may be specified multiple times",
84 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
85 listeners << address
86 end
88 opts.on("-c", "--config-file FILE",
89 "Rainbows!/Unicorn-specific config file") do |f|
90 options[:config_file] = f
91 end
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, '')
102 exit
105 opts.on_tail("-v", "--version", "Show version") do
106 puts "Rainbows! v#{Rainbows::Const::RAINBOWS_VERSION}"
107 exit
110 opts.parse! ARGV
113 app = Unicorn.builder(ARGV[0] || 'config.ru', opts)
114 listeners << "#{host}:#{port}" if set_listener
116 if $DEBUG
117 require 'pp'
118 pp({
119 :unicorn_options => options,
120 :app => app,
121 :daemonize => daemonize,
125 Unicorn::Launcher.daemonize!(options) if daemonize
126 Rainbows.run(app, options)