diff --git a/lib/gems/pending/appliance_console/database_replication_standby.rb b/lib/gems/pending/appliance_console/database_replication_standby.rb index 35442429d..b6483f409 100644 --- a/lib/gems/pending/appliance_console/database_replication_standby.rb +++ b/lib/gems/pending/appliance_console/database_replication_standby.rb @@ -62,6 +62,8 @@ def ask_for_repmgrd_configuration def activate say("Configuring Replication Standby Server...") + stop_postgres + stop_repmgrd initialize_postgresql_disk if disk PostgresAdmin.prep_data_directory if disk || resync_data generate_cluster_name && @@ -102,6 +104,11 @@ def start_postgres true end + def stop_postgres + LinuxAdmin::Service.new(PostgresAdmin.service_name).stop + true + end + def register_standby_server run_repmgr_command(REGISTER_CMD, :force => nil) end @@ -116,6 +123,11 @@ def start_repmgrd false end + def stop_repmgrd + LinuxAdmin::Service.new(REPMGRD_SERVICE).stop + true + end + def node_number_valid? rec = record_for_node_number diff --git a/spec/appliance_console/database_replication_standby_spec.rb b/spec/appliance_console/database_replication_standby_spec.rb index 6f2ffeace..958014370 100644 --- a/spec/appliance_console/database_replication_standby_spec.rb +++ b/spec/appliance_console/database_replication_standby_spec.rb @@ -117,6 +117,8 @@ context "#activate" do before do + expect(subject).to receive(:stop_postgres) + expect(subject).to receive(:stop_repmgrd) expect(subject).to receive(:generate_cluster_name).and_return(true) expect(subject).to receive(:create_config_file).and_return(true) expect(subject).to receive(:clone_standby_server).and_return(true) @@ -245,6 +247,16 @@ end end + context "#stop_postgres" do + it "should stop postgres and return true" do + service = double("PostgresService", :service => nil) + expect(LinuxAdmin::Service).to receive(:new).and_return(service) + expect(service).to receive(:stop) + + expect(subject.stop_postgres).to be_truthy + end + end + context "#start_repmgrd" do it "starts and enables repmgrd" do service = double(SPEC_NAME) @@ -264,6 +276,16 @@ end end + context "#stop_repmgrd" do + it "stops the repmgrd service" do + service = double("RepmgrdService") + expect(LinuxAdmin::Service).to receive(:new).and_return(service) + expect(service).to receive(:stop) + + expect(subject.stop_repmgrd).to be true + end + end + context "#node_number_valid?" do let(:node_number) { 1 } let(:connection) { double("PG::Connection") }