878b3f20e4ccda77312ec8b4c05e139f33e4c7cc
[rainbows.git] / bin / rainbows
blob878b3f20e4ccda77312ec8b4c05e139f33e4c7cc
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("-D", "--daemonize", "run daemonized in the background") do |d|
63 rackup_opts[:daemonize] = !!d
64 end
66 opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
67 warn "Use of --pid/-P is strongly discouraged"
68 warn "Use the 'pid' directive in the Rainbows!/Unicorn config file instead"
69 options[:pid] = f
70 end
72 opts.on("-s", "--server SERVER",
73 "this flag only exists for compatibility") do |s|
74 warn "-s/--server only exists for compatibility with rackup"
75 end
77 # Rainbows!/Unicorn-specific stuff
78 opts.on("-l", "--listen {HOST:PORT|PATH}",
79 "listen on HOST:PORT or PATH",
80 "this may be specified multiple times",
81 "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
82 options[:listeners] << address
83 end
85 opts.on("-c", "--config-file FILE", "Rainbows!-specific config file") do |f|
86 options[:config_file] = f
87 end
89 # I'm avoiding Unicorn-specific config options on the command-line.
90 # IMNSHO, config options on the command-line are redundant given
91 # config files and make things unnecessarily complicated with multiple
92 # places to look for a config option.
94 opts.separator "Common options:"
96 opts.on_tail("-h", "--help", "Show this message") do
97 puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
98 exit
99 end
101 opts.on_tail("-v", "--version", "Show version") do
102 puts "Rainbows! v#{Rainbows::Const::RAINBOWS_VERSION}"
103 exit
106 opts.parse! ARGV
109 app = Unicorn.builder(ARGV[0] || 'config.ru', op)
110 op = nil
112 if $DEBUG
113 require 'pp'
114 pp({
115 :unicorn_options => options,
116 :app => app,
117 :daemonize => rackup_opts[:daemonize],
121 Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
122 Rainbows::HttpServer.new(app, options).start.join