bin/zbatery in zbatery-0.3.1 vs bin/zbatery in zbatery-0.4.0
- old
+ new
@@ -1,22 +1,19 @@
-#!/usr/bin/ruby
+#!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
# -*- encoding: binary -*-
require 'unicorn/launcher'
require 'zbatery'
require 'optparse'
ENV["RACK_ENV"] ||= "development"
-daemonize = false
-listeners = []
-options = { :listeners => listeners }
-host, port = Unicorn::Const::DEFAULT_HOST, Unicorn::Const::DEFAULT_PORT
-set_listener = false
+rackup_opts = Unicorn::Configurator::RACKUP
+options = rackup_opts[:options]
opts = OptionParser.new("", 24, ' ') do |opts|
- opts.banner = "Usage: #{File.basename($0)} " \
- "[ruby options] [zbatery options] [rackup config file]"
-
+ cmd = File.basename($0)
+ opts.banner = "Usage: #{cmd} " \
+ "[ruby options] [#{cmd} options] [rackup config file]"
opts.separator "Ruby options:"
lineno = 1
opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
eval line, TOPLEVEL_BINDING, "-e", lineno
@@ -39,55 +36,55 @@
opts.on("-r", "--require LIBRARY",
"require the library, before executing your script") do |library|
require library
end
- opts.separator "Zbatery options:"
+ opts.separator "#{cmd} options:"
# some of these switches exist for rackup command-line compatibility,
opts.on("-o", "--host HOST",
"listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h|
- host = h
- set_listener = true
+ rackup_opts[:host] = h
+ rackup_opts[:set_listener] = true
end
opts.on("-p", "--port PORT",
"use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |p|
- port = p.to_i
- set_listener = true
+ rackup_opts[:port] = p.to_i
+ rackup_opts[:set_listener] = true
end
- opts.on("-E", "--env ENVIRONMENT",
- "use ENVIRONMENT for defaults (default: development)") do |e|
+ opts.on("-E", "--env RACK_ENV",
+ "use RACK_ENV for defaults (default: development)") do |e|
ENV["RACK_ENV"] = e
end
opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
- daemonize = d ? true : false
+ rackup_opts[:daemonize] = !!d
end
opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
- warn %q{Use of --pid/-P is strongly discouraged}
- warn %q{Use the 'pid' directive in the Zbatery config file instead}
+ warn "Use of --pid/-P is strongly discouraged"
+ warn "Use the 'pid' directive in the Zbatery config file instead"
options[:pid] = f
end
opts.on("-s", "--server SERVER",
"this flag only exists for compatibility") do |s|
warn "-s/--server only exists for compatibility with rackup"
end
- # Zbatery/Unicorn-specific stuff
+ # Rainbows!/Unicorn-specific stuff
opts.on("-l", "--listen {HOST:PORT|PATH}",
"listen on HOST:PORT or PATH",
"this may be specified multiple times",
"(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
- listeners << address
+ options[:listeners] << address
end
- opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
+ opts.on("-c", "--config-file FILE", "Zbatery-specific config file") do |f|
options[:config_file] = f
end
# I'm avoiding Unicorn-specific config options on the command-line.
# IMNSHO, config options on the command-line are redundant given
@@ -100,29 +97,25 @@
puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
exit
end
opts.on_tail("-v", "--version", "Show version") do
- puts "zbatery v#{Zbatery::VERSION}"
+ puts "Zbatery v#{Zbatery::VERSION}"
exit
end
opts.parse! ARGV
end
-config = ARGV[0] || "config.ru"
-abort "configuration file #{config} not found" unless File.exist?(config)
+app = Unicorn.builder(ARGV[0] || 'config.ru', opts)
-app = Unicorn.builder(config, opts)
-listeners << "#{host}:#{port}" if set_listener
-
if $DEBUG
require 'pp'
pp({
- :zbatery_options => options,
+ :unicorn_options => options,
:app => app,
- :daemonize => daemonize,
+ :daemonize => rackup_opts[:daemonize],
})
end
-Unicorn::Launcher.daemonize!(options) if daemonize
+Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
Zbatery.run(app, options)