Class: Deadpool::Server
- Inherits:
-
Object
- Object
- Deadpool::Server
- Includes:
- Daemonizer
- Defined in:
- lib/deadpool/server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #load_handlers ⇒ Object
- #load_plugins ⇒ Object
- #promote_server(pool_name, server) ⇒ Object
- #run(daemonize) ⇒ Object
- #schedule_system_check ⇒ Object
- #start_command_server ⇒ Object
- #start_deadpool_handlers ⇒ Object
- #system_check(force = false) ⇒ Object
Methods included from Daemonizer
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/deadpool/server.rb', line 13 def initialize() @options = @state = Deadpool::State.new self.class.to_s @config = Deadpool::Helper.configure(@options) @logger = Deadpool::Helper.setup_logger(@config) # if @options[:daemonize] # options = @options[:pid_file].nil? ? {} : {:pid => @options[:pid_file]} # self.daemonize options # end # # load_handlers # start_deadpool_handlers # start_command_server # schedule_system_check end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/deadpool/server.rb', line 11 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/deadpool/server.rb', line 10 def logger @logger end |
Instance Method Details
#load_handlers ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/deadpool/server.rb', line 55 def load_handlers @handlers = {} @state.set_state(OK, 'Loading Handlers.') Dir[@options[:config_path] + '/config/pools/*.yml'].each do |pool_yml| pool_config = Deadpool::Helper.symbolize_keys YAML.load(File.read(pool_yml)) @handlers[pool_config[:pool_name]] = Deadpool::Handler.new(pool_config, logger) end @state.set_state(OK, 'Handlers loaded.') end |
#load_plugins ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/deadpool/server.rb', line 44 def load_plugins failover_plugin_dir = File.join @options[:config_path], 'lib', 'deadpool', 'failover_protocol' monitor_plugin_dir = File.join @options[:config_path], 'lib', 'deadpool', 'monitor' [failover_plugin_dir, monitor_plugin_dir].each do |plugin_dir| Dir[plugin_dir + '/*.rb'].each do |filename| require filename end end end |
#promote_server(pool_name, server) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/deadpool/server.rb', line 100 def promote_server(pool_name, server) unless @handlers[pool_name].nil? # logger.debug "Pool Name: #{pool_name}, Server: #{server}" return @handlers[pool_name].promote_server server else logger.error "'#{pool_name}' pool not found." return false end end |
#run(daemonize) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/deadpool/server.rb', line 30 def run(daemonize) EventMachine::run { if daemonize = @options[:pid_file].nil? ? {} : {:pid => @options[:pid_file]} self.daemonize end load_handlers start_deadpool_handlers start_command_server schedule_system_check } end |
#schedule_system_check ⇒ Object
75 76 77 78 79 |
# File 'lib/deadpool/server.rb', line 75 def schedule_system_check timer = EventMachine::PeriodicTimer.new(@config[:system_check_interval]) do system_check(true) end end |
#start_command_server ⇒ Object
81 82 83 84 85 |
# File 'lib/deadpool/server.rb', line 81 def start_command_server EventMachine::start_server @config[:admin_hostname], @config[:admin_port], Deadpool::AdminServer do |connection| connection.deadpool_server = self end end |
#start_deadpool_handlers ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/deadpool/server.rb', line 67 def start_deadpool_handlers @handlers.each_value do |handler| timer = EventMachine::PeriodicTimer.new(handler.check_interval) do handler.monitor_pool(timer) end end end |
#system_check(force = false) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/deadpool/server.rb', line 87 def system_check(force=false) if force || @cached_state_snapshot.nil? @state.reset! @cached_state_snapshot = Deadpool::StateSnapshot.new @state @handlers.each_value do |handler| @cached_state_snapshot.add_child handler.system_check end end return @cached_state_snapshot end |