#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../ruby_lib/ebb'
require 'optparse'
options = {
:root => Dir.pwd,
:env => 'development',
:hort => '0.0.0.0',
:port => 3000,
:timeout => 60,
:log_file => 'log/ebb.log',
:pid_file => 'tmp/pids/ebb.pid'
}
opts = OptionParser.new do |opts|
opts.banner = "Usage: ebb_rails [options] start|stop"
opts.separator ""
opts.separator "Server options:"
opts.on("-s", "--socket SOCKET", "listen on socket") { |socket| options[:socket] = socket }
opts.on("-p", "--port PORT", "use PORT (default: 3000)") { |port| options[:port] = port }
opts.on("-e", "--env ENV", "Rails environment (default: development)") { |env| options[:env] = env }
opts.on("-c", "--chdir PATH", "Rails root dir (default: current dir)") { |dir| options[:root] = dir }
opts.on("-d", "--daemonize", "Daemonize") { options[:daemonize] = true }
opts.on("-l", "--log-file FILE", "File to redirect output",
"(default: #{options[:log_file]})") { |file| options[:log_file] = file }
opts.on("-P", "--pid-file FILE", "File to store PID",
"(default: #{options[:pid_file]})") { |file| options[:pid_file] = file }
opts.on("-t", "--timeout SEC", "Request or command timeout in sec",
"(default: #{options[:timeout]})") { |sec| options[:timeout] = sec; raise NotImplementedError } # TODO: fix me
opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail('-v', '--version', "Show version") do
puts "Ebb #{Ebb::VERSION}"
exit
end
opts.parse! ARGV
end
case ARGV[0]
when 'start'
app = Rack::Adapter::Rails.new(options)
server = Ebb::Server.new(app, options)
server.pid_file = options[:pid_file]
server.log_file = options[:log_file]
# server.timeout = options[:timeout]
if options[:daemonize]
server.change_privilege options[:user], options[:group] if options[:user] && options[:group]
server.daemonize
end
server.start
when 'stop'
Ebb::Server.kill options[:pid_file], options[:timeout]
when nil
puts "Command required"
puts opts
exit 1
else
abort "Invalid command : #{ARGV[0]}"
end