build: automatically call isolate on updates
[unicorn.git] / bin / unicorn
blob86c938b843fa9da1b0440a5783bb493c515904be
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 opts = 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', opts)
110 if $DEBUG
111 require 'pp'
112 pp({
113 :unicorn_options => options,
114 :app => app,
115 :daemonize => rackup_opts[:daemonize],
119 Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
120 Unicorn.run(app, options)