lib/magpie/server.rb in magpie-0.8.6.2 vs lib/magpie/server.rb in magpie-0.8.8
- old
+ new
@@ -1,5 +1,6 @@
+# -*- coding: utf-8 -*-
module Magpie
class Server < Rack::Server
class Options
def parse!(args)
@@ -27,10 +28,18 @@
opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
options[:pid] = f
}
+ opts.on("-M", "--mode MODE", "开启magpie模式选项(snake, bird 默认模式是snake)"){ |mode|
+ options[:mode] = mode
+ }
+
+ opts.on("-L", "--log logfile", "指定日志文件"){ |logfile|
+ options[:log] = logfile
+ }
+
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
@@ -47,21 +56,27 @@
options
end
end
def app
- Magpie::APP
+ require 'apps'
+ case self.options[:mode]
+ when "snake"; SNAKE_APP
+ when "bird"; BIRD_APP
+ end
end
def default_options
{
:environment => "development",
:pid => nil,
:Port => 9292,
:Host => "0.0.0.0",
:AccessLog => [],
- :yml => "magpie.yml"
+ :yml => "magpie.yml",
+ :mode => "snake",
+ :log => "magpie.log"
}
end
private
def opt_parser
@@ -72,9 +87,10 @@
options = super
if !::File.exist? options[:yml]
abort "configuration file #{options[:yml]} not found"
end
Magpie.yml_db = ::YAML.load_file(options[:yml])
+ Magpie.logger = ::Logger.new(options[:log])
options
end
end
end