#!/usr/bin/ruby require 'rbtrace' require 'yaml' opts = YAML::load_file(File.join(__dir__,'opts.yaml')) opts[:pidf] = __FILE__ + '.pid' opts[:pid] = Process.pid global_controller = File.join(opts[:global_executionhandlers],opts[:executionhandler],'controller.rb') controller = File.join(opts[:executionhandlers], opts[:executionhandler],'controller.rb') if File.exist? global_controller require global_controller elsif File.exist? controller require controller end global_connectionhandler = File.join(opts[:global_executionhandlers],opts[:executionhandler],'connection.rb') connectionhandler = File.join(opts[:executionhandlers], opts[:executionhandler],'connection.rb') if File.exist? global_connectionhandler require global_connectionhandler elsif File.exist? connectionhandler require connectionhandler end require_relative 'instance' controller = Controller.new(File.basename(__dir__).to_i, __dir__, opts) controller.instance = Instance.new controller File.write(opts[:pidf],opts[:pid]) %w{TERM HUP INT}.each do |sig| Signal.trap(sig) do puts "Caught #{sig}!" controller.stop end end controller.start File.unlink(opts[:pidf])