add version file
[ebb.git] / bin / ebb_rails
blob340203186c55eaa840ad196cf5f8df6248ab3c15
1 #!/usr/bin/env ruby
2 require File.dirname(__FILE__) + '/../ruby_lib/ebb'
3 require 'optparse'
5 options = {
6 :root => Dir.pwd,
7 :env => 'development',
8 :hort => '0.0.0.0',
9 :port => 3000,
10 :timeout => 60,
11 :log_file => 'log/ebb.log',
12 :pid_file => 'tmp/pids/ebb.pid'
15 opts = OptionParser.new do |opts|
16 opts.banner = "Usage: ebb_rails [options] start|stop"
18 opts.separator ""
19 opts.separator "Server options:"
21 opts.on("-s", "--socket SOCKET", "listen on socket") { |socket| options[:socket] = socket }
22 opts.on("-p", "--port PORT", "use PORT (default: 3000)") { |port| options[:port] = port }
23 opts.on("-e", "--env ENV", "Rails environment (default: development)") { |env| options[:env] = env }
24 opts.on("-c", "--chdir PATH", "Rails root dir (default: current dir)") { |dir| options[:root] = dir }
25 opts.on("-d", "--daemonize", "Daemonize") { options[:daemonize] = true }
26 opts.on("-l", "--log-file FILE", "File to redirect output",
27 "(default: #{options[:log_file]})") { |file| options[:log_file] = file }
28 opts.on("-P", "--pid-file FILE", "File to store PID",
29 "(default: #{options[:pid_file]})") { |file| options[:pid_file] = file }
30 opts.on("-t", "--timeout SEC", "Request or command timeout in sec",
31 "(default: #{options[:timeout]})") { |sec| options[:timeout] = sec; raise NotImplementedError } # TODO: fix me
32 opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
33 opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
35 opts.separator ""
36 opts.separator "Common options:"
38 opts.on_tail("-h", "--help", "Show this message") do
39 puts opts
40 exit
41 end
43 opts.on_tail('-v', '--version', "Show version") do
44 puts "Ebb #{Ebb::VERSION}"
45 exit
46 end
48 opts.parse! ARGV
49 end
51 case ARGV[0]
53 when 'start'
54 app = Rack::Adapter::Rails.new(options)
55 server = Ebb::Server.new(app, options)
57 server.pid_file = options[:pid_file]
58 server.log_file = options[:log_file]
59 # server.timeout = options[:timeout]
61 if options[:daemonize]
62 server.change_privilege options[:user], options[:group] if options[:user] && options[:group]
63 server.daemonize
64 end
66 server.start
68 when 'stop'
69 Ebb::Server.kill options[:pid_file], options[:timeout]
71 when nil
72 puts "Command required"
73 puts opts
74 exit 1
76 else
77 abort "Invalid command : #{ARGV[0]}"
79 end