Class: Deadpool::FailoverProtocol::ExecRemoteCommand
- Defined in:
- lib/deadpool/failover_protocol/exec_remote_command.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#preflight_check ⇒ Object
Return true or false Don’t update system state.
-
#promote_to_primary(new_primary) ⇒ Object
Promote the host to primary.
- #setup ⇒ Object
-
#system_check ⇒ Object
Perform checks against anything that could cause a failover protocol to fail Perform checks on system state.
- #test_client(client_host) ⇒ Object
Methods inherited from Base
#initialize, #initiate_failover_protocol!
Constructor Details
This class inherits a constructor from Deadpool::FailoverProtocol::Base
Instance Method Details
#preflight_check ⇒ Object
Return true or false Don’t update system state. return true or false success or failure
22 23 24 |
# File 'lib/deadpool/failover_protocol/exec_remote_command.rb', line 22 def preflight_check @client_hosts.all? { |client_host| test_client(client_host) } end |
#promote_to_primary(new_primary) ⇒ Object
Promote the host to primary. This is used by initiate_failover_protocol! and for manual promotion by an administrator. new_primary is an IP address TODO: change new_primary to be a config label. return true or false success or failure
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deadpool/failover_protocol/exec_remote_command.rb', line 36 def promote_to_primary(new_primary) success = true @client_hosts.each do |client_host| if exec_remote_command(@exec_command, client_host) exec_remote_command(@exec_command, client_host) logger.info "Promotion exec command succeeded on #{client_host}" else logger.error "Promotion exec command failed on #{client_host}" end end return success end |
#setup ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/deadpool/failover_protocol/exec_remote_command.rb', line 9 def setup @test_command = @failover_config[:test_command] @exec_command = @failover_config[:exec_command] @client_hosts = @failover_config[:client_hosts] @username = @failover_config[:username] @password = @failover_config[:password] @use_sudo = @failover_config[:use_sudo] @sudo_path = @failover_config[:sudo_path].nil? ? 'sudo' : @failover_config[:sudo_path] end |
#system_check ⇒ Object
Perform checks against anything that could cause a failover protocol to fail Perform checks on system state. return New Deadpool::StateSnapshot
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/deadpool/failover_protocol/exec_remote_command.rb', line 54 def system_check failed = [] succeeded = [] # Collect check data @client_hosts.each do |client_host| if test_client(client_host) succeeded << client_host else failed << client_host end end # Compile write check data. if !succeeded.empty? && failed.empty? @state.set_state OK, "Exec test passed all servers: #{succeeded.join(', ')}" elsif !succeeded.empty? && !failed.empty? @state.set_state WARNING, "Exec test passed on: #{succeeded.join(', ')}" @state. "Exec test failed on #{failed.join(', ')}" elsif succeeded.empty? @state.set_state WARNING, "Exec test failed all servers: #{failed.join(', ')}" end return Deadpool::StateSnapshot.new @state end |
#test_client(client_host) ⇒ Object
26 27 28 29 |
# File 'lib/deadpool/failover_protocol/exec_remote_command.rb', line 26 def test_client(client_host) logger.debug "Testing Client #{client_host}" return exec_remote_command(@test_command, client_host) end |