lib/envoy/client/command.rb in envoy-proxy-0.2.3 vs lib/envoy/client/command.rb in envoy-proxy-1.0.0

- old
+ new

@@ -1,62 +1,23 @@ require 'envoy/client/trunk' -require 'envoy/client/option_parser' +require 'envoy/client/config' require 'envoy/version' -require 'yaml' -def find_config - dirs = Dir.pwd.split("/") - r = dirs.reduce([]) do |m, x| - [[*m[0], x], *m] - end.map do |p| - p.join("/") + "/.envoy" - end.each do |p| - return p if File.exist?(p) - end - false -end +class Envoy::Client::Command -def load_config - if path = find_config - conf = YAML.load(File.read(path)) - Array(conf).each do |conf| - if conf["rails"] - conf["dir"] = conf["rails"] - conf["pidfile"] = "tmp/pids/server.pid" - conf["command"] = "rails s -p %{local_port}" - conf["delay"] = 10 - elsif conf["rackup"] - conf["dir"] = conf["rackup"] - conf["command"] = "rackup -p %{local_port}" - conf["delay"] = 10 - end - conf["host"] ||= conf["dir"].split("/")[-1] if conf["dir"] - conf["dir"] = File.expand_path(conf["dir"], path + "/..") if conf["dir"] - end - else - [{}] - end -end - -options = parse_options - -unless EM.reactor_running? - EM.run do - Signal.trap("INT") do - $exiting = true - EventMachine.stop - end - Signal.trap("TERM") do - $exiting = true - EventMachine.stop - end - load_config.each do |config| - config = config.merge(options) - config["local_port"] ||= config["command"] ? rand(16383) + 49152 : 80 - config["hosts"] ||= [config.delete("host")] if config["host"] - config = config.each_with_object({}) do |(k, v), h| - h[k.to_sym] = v - end + def run (args) + EM.run do + Envoy.verbosity = Envoy::INFO + stopper = proc { $exiting = true; EventMachine.stop } + Signal.trap("INT", stopper) + Signal.trap("TERM", stopper) + Envoy.log(Envoy::DEBUG, "envoy #{Envoy::VERSION} starting up") + config = Envoy::Client::Config.new + config.parse_options + config.parse_envoyfile + config.infer_sane_defaults + config.start_service Envoy::Client::Trunk.start config end end + end