Class: ActivePostgres::Failover
- Inherits:
-
Object
- Object
- ActivePostgres::Failover
- Defined in:
- lib/active_postgres/failover.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#ssh_executor ⇒ Object
readonly
Returns the value of attribute ssh_executor.
Instance Method Summary collapse
-
#initialize(config) ⇒ Failover
constructor
A new instance of Failover.
- #promote(host_or_node) ⇒ Object
Constructor Details
#initialize(config) ⇒ Failover
Returns a new instance of Failover.
5 6 7 8 |
# File 'lib/active_postgres/failover.rb', line 5 def initialize(config) @config = config @ssh_executor = SSHExecutor.new(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/active_postgres/failover.rb', line 3 def config @config end |
#ssh_executor ⇒ Object (readonly)
Returns the value of attribute ssh_executor.
3 4 5 |
# File 'lib/active_postgres/failover.rb', line 3 def ssh_executor @ssh_executor end |
Instance Method Details
#promote(host_or_node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_postgres/failover.rb', line 10 def promote(host_or_node) # Determine target host target_host = resolve_host(host_or_node) raise Error, "Could not resolve host: #{host_or_node}" unless target_host raise Error, "Host is not a standby: #{target_host}" unless config.standby_hosts.include?(target_host) puts "==> Promoting #{target_host} to primary..." puts puts 'WARNING: This will promote the standby to primary.' puts 'Make sure to update your database.yml and restart your application.' puts print 'Continue? (y/N): ' response = $stdin.gets.chomp unless response.downcase == 'y' puts 'Cancelled.' return end # Perform promotion if config.component_enabled?(:repmgr) promote_with_repmgr(target_host) else promote_manual(target_host) end puts "\n✓ Promotion complete!" puts "\nNext steps:" puts " 1. Update database.yml to point to new primary: #{target_host}" puts ' 2. Restart your application' puts ' 3. Rebuild old primary as new standby (if needed)' end |