Class: Anobik::Server
- Inherits:
-
Object
- Object
- Anobik::Server
- Defined in:
- lib/anobik/server.rb
Class Method Summary collapse
-
.run ⇒ Object
Runs the Anobik middleware app.
Class Method Details
.run ⇒ Object
Runs the Anobik middleware app
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 |
# File 'lib/anobik/server.rb', line 9 def self.run #partially stolen from Rails = { :Port => 9291, :Host => "0.0.0.0", :detach => false, :debugger => false, :production => false } ARGV.clone. do |option| option.on("-p", "--port=port", Integer, "Runs Server on the specified port.", "Default: #{[:Port]}") { |v| [:Port] = v } option.on("-b", "--binding=ip", String, "Binds Server to the specified ip.", "Default: #{[:Host]}") { |v| [:Host] = v } option.on("-d", "--daemon", "Make server run as a Daemon.") { [:detach] = true } option.on("-x", "--production", "Run the server in production mode.") { [:production] = true } option.on("-u", "--debugger", "Enable rack server debugging.") { [:debugger] = true } option.separator "" option.on("-h", "--help", "Show this help message.") { puts option.help; exit } option.parse! end unless server = Rack::Handler.get(ARGV.first) rescue nil begin server = Rack::Handler::Mongrel rescue LoadError => e server = Rack::Handler::WEBrick end end puts "=> Booting with #{server}" puts "=> Running in production mode" if [:production] puts "=> Application starting on http://#{[:Host]}:#{[:Port]}#{[:path]}" if [:detach] puts "=> Running as deamon with pid: #{Process.pid}" Process.daemon else puts "=> Call with -d to detach" end app = Anobik::App::create [:debugger], [:production] trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" begin server.run app, .merge(:AccessLog => []) ensure puts "Exiting" end end |