Class: ManageIQ::ApplianceConsole::DatabaseReplicationStandby
Constant Summary
collapse
- REGISTER_CMD =
'repmgr standby register'.freeze
ManageIQ::ApplianceConsole::DatabaseReplication::NETWORK_INTERFACE, ManageIQ::ApplianceConsole::DatabaseReplication::PGPASS_FILE, ManageIQ::ApplianceConsole::DatabaseReplication::REPGMR_FILE_LOCATIONS
Instance Attribute Summary collapse
#database_name, #database_password, #database_user, #node_number, #primary_host
Instance Method Summary
collapse
Methods included from Logging
#error_and_logging_from_command_result_error, #error_and_logging_from_standard_error, #interactive, #interactive=, interactive?, #interactive?, #log_and_feedback, #log_and_feedback_exception, #log_and_feedback_info, #log_error, #log_prefix, #logger, #logger=, #say_error, #say_info
#ask_for_database_credentials, #ask_for_unique_cluster_node_number, #config_file_contents, #confirm_reconfiguration, #create_config_file, repmgr_config, repmgr_configured?, repmgr_file_locations, repmgr_log, repmgr_service_name, #write_pgpass_file
Constructor Details
Returns a new instance of DatabaseReplicationStandby.
14
15
16
17
18
19
20
21
22
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 14
def initialize
self.node_number = nil
self.database_name = "vmdb_production"
self.database_user = "root"
self.database_password = nil
self.primary_host = nil
self.standby_host = LinuxAdmin::NetworkInterface.new(NETWORK_INTERFACE).address
self.resync_data = false
end
|
Instance Attribute Details
#disk ⇒ Object
Returns the value of attribute disk.
12
13
14
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 12
def disk
@disk
end
|
#force_register ⇒ Object
Returns the value of attribute force_register.
12
13
14
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 12
def force_register
@force_register
end
|
#resync_data ⇒ Object
Returns the value of attribute resync_data.
12
13
14
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 12
def resync_data
@resync_data
end
|
#run_repmgrd_configuration ⇒ Object
Returns the value of attribute run_repmgrd_configuration.
12
13
14
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 12
def run_repmgrd_configuration
@run_repmgrd_configuration
end
|
#standby_host ⇒ Object
Returns the value of attribute standby_host.
12
13
14
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 12
def standby_host
@standby_host
end
|
Instance Method Details
#activate ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 58
def activate
say("Configuring Replication Standby Server...")
stop_postgres
stop_repmgrd
initialize_postgresql_disk if disk
PostgresAdmin.prep_data_directory if disk || resync_data
relabel_postgresql_dir
save_database_yml
create_config_file(standby_host) &&
write_pgpass_file &&
clone_standby_server &&
start_postgres &&
register_standby_server &&
(run_repmgrd_configuration ? start_repmgrd : true)
end
|
#ask_for_repmgrd_configuration ⇒ Object
54
55
56
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 54
def ask_for_repmgrd_configuration
self.run_repmgrd_configuration = ask_yn?("Configure Replication Manager (repmgrd) for automatic failover")
end
|
#ask_for_standby_host ⇒ Object
50
51
52
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 50
def ask_for_standby_host
self.standby_host = ask_for_ip_or_hostname("Standby Server hostname or IP address", standby_host)
end
|
#ask_questions ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 24
def ask_questions
clear_screen
say("Establish Replication Standby Server\n")
return false if !data_dir_empty? && !confirm_data_resync
self.disk = ask_for_disk("Standby database disk")
ask_for_unique_cluster_node_number
ask_for_database_credentials
ask_for_standby_host
ask_for_repmgrd_configuration
return false unless node_number_valid?
return false if repmgr_configured? && !confirm_reconfiguration
confirm
end
|
#clone_standby_server ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 88
def clone_standby_server
params = { :h => primary_host,
:U => database_user,
:d => database_name,
:D => PostgresAdmin.data_directory,
nil => %w(standby clone)
}
run_repmgr_command("repmgr", params)
end
|
#confirm ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 38
def confirm
super
say(<<-EOS) if disk
Database Disk: #{disk.path}
EOS
say(<<-EOS)
Standby Host: #{standby_host}
Automatic Failover: #{run_repmgrd_configuration ? "enabled" : "disabled"}
EOS
agree("Apply this Replication Server Configuration? (Y/N): ")
end
|
#confirm_data_resync ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 78
def confirm_data_resync
logger.info("Appliance database found under: #{PostgresAdmin.data_directory}")
say("")
say("Appliance database found under: #{PostgresAdmin.data_directory}")
say("Replication standby server can not be configured if the database already exists")
say("Would you like to remove the existing database before configuring as a standby server?")
say(" WARNING: This is destructive. This will remove all previous data from this server")
self.resync_data = ask_yn?("Continue")
end
|
#data_dir_empty? ⇒ Boolean
74
75
76
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 74
def data_dir_empty?
Dir[PostgresAdmin.data_directory.join("*")].empty?
end
|
#node_number_valid? ⇒ Boolean
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 127
def node_number_valid?
rec = record_for_node_number
return true if rec.nil?
node_state = rec["active"] ? "active" : "inactive"
say("An #{node_state} #{rec["type"]} node (#{rec["node_name"]}) with the node number #{node_number} already exists")
ask_yn?("Would you like to continue configuration by overwriting the existing node", "N")
rescue PG::Error => e
error_msg = "Failed to validate node number #{node_number}. #{e.message}"
say(error_msg)
logger.error(error_msg)
return false
end
|
#register_standby_server ⇒ Object
108
109
110
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 108
def register_standby_server
run_repmgr_command(REGISTER_CMD, :force => nil, :wait_sync= => 60)
end
|
#start_postgres ⇒ Object
98
99
100
101
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 98
def start_postgres
LinuxAdmin::Service.new(PostgresAdmin.service_name).enable.start
true
end
|
#start_repmgrd ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 112
def start_repmgrd
LinuxAdmin::Service.new(repmgr_service_name).enable.start
true
rescue AwesomeSpawn::CommandResultError => e
message = "Failed to start repmgrd: #{e.message}"
logger.error(message)
say(message)
false
end
|
#stop_postgres ⇒ Object
103
104
105
106
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 103
def stop_postgres
LinuxAdmin::Service.new(PostgresAdmin.service_name).stop
true
end
|
#stop_repmgrd ⇒ Object
122
123
124
125
|
# File 'lib/manageiq/appliance_console/database_replication_standby.rb', line 122
def stop_repmgrd
LinuxAdmin::Service.new(repmgr_service_name).stop
true
end
|