38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/phprpc/mongrel_server.rb', line 38
def initialize(options = {})
@options = {
:host => '0.0.0.0',
:port => 3000,
:num_processors => 1024,
:throttle => 0,
:timeout => 60,
:debug => false,
:daemonize => false,
:cwd => Dir.pwd,
:log_file => 'log/mongrel.log',
:pid_file => 'log/mongrel.pid',
:session_mode => :file,
:path => '/',
:expire_after => 1800,
}.update(options)
@opts = OptionParser.new
@opts.banner = "Usage: #{@opts.program_name} mongrel [options]"
@opts.separator ""
@opts.separator "Server options:"
@opts.on('-a', '--address IP', String, "Address to bind to (default: #{@options[:host]})") { |ip| @options[:host] = ip }
@opts.on('-p', '--port PORT', Integer, "Which port to bind to (default: #{@options[:port]})") { |port| @options[:port] = port }
@opts.on('-c', '--chdir PATH', String, "Change to dir before starting", "(will be expanded) (default: #{@options[:cwd]})") { |path| @options[:cwd] = File.expand_path(path) }
@opts.on('-u', '--user USER', String, "User to run as") { |user| @options[:user] = user }
@opts.on('-g', '--group GROUP', String, "Group to run as") { |group| @options[:group] = group }
unless RUBY_PLATFORM =~ /mswin|mingw/ @opts.separator ""
@opts.separator "Daemon options:"
@opts.on('-d', '--daemonize', "Run daemonized in the background") { @options[:daemonize] = true }
@opts.on('-l', '--log FILE', String, "Where to write log messages", "(default: #{@options[:log_file]})") { |file| @options[:log_file] = file }
@opts.on("-P", "--pid FILE", String, "File to store PID", "(default: #{@options[:pid_file]})") { |file| @options[:pid_file] = file }
end
@opts.separator ""
@opts.separator "Tuning options:"
@opts.on('-n', '--num-processors INT', Integer, "Number of processors active", "before clients denied (default: #{@options[:num_processors]})") { |num| @options[:num_processors] = num }
@opts.on('-t', '--throttle TIME', Integer, "Time to pause (in hundredths of a second)", "between accepting clients (default: #{@options[:throttle]})") { |time| @options[:throttle] = time }
@opts.on('-o', '--timeout TIME', Integer, "Time to wait (in seconds) before killing", "a stalled thread (default: #{@options[:timeout]})") { |time| @options[:timeout] = time }
@opts.separator ""
@opts.separator "Session options:"
@opts.on('-s', '--session-mode MODE', [:file, :memcache, :pool], "Select Session mode (file, memcache, pool)", "(default: #{@options[:session_mode].to_s})") { |mode| @options[:session_mode] = mode }
@opts.on('-e','--expire-after TIME', Integer, "Session expire after (default: #{@options[:expire_after]})") { |time| @options[:expire_after] = time }
@opts.on('-m','--memcache_server SERVER', String, "Memcache server used by session in", "memcache mode (default: localhost:11211)") { |server| @options[:memcache_server] = server }
@opts.on('--prefix PATH', String, "Mount the PHPRPC Server under PATH", "(start with /)") { |path| @options[:path] = path }
@opts.separator ""
@opts.separator "Common options:"
@opts.on_tail('-D', '--debug', "Set debbuging on (default: disabled)") { @options[:debug] = true }
@opts.on_tail('-?', '-h', '--help', "Show this help message.") { puts @opts; exit }
@opts.on_tail('-v', '--version', "Show version") { puts "Mongrel web server v#{Mongrel::Const::MONGREL_VERSION}"; exit }
begin
@opts.parse!(ARGV)
rescue OptionParser::ParseError
puts @opts
exit
end
@app = PHPRPC::BaseServer.new
@app.debug = @options[:debug]
end
|