Skip to content

Commit

Permalink
Merge pull request #142 from carbonin/stop_pg_and_repmgr_for_standby_…
Browse files Browse the repository at this point in the history
…config

Stop the postgres and repmgr services before configuring a standby
  • Loading branch information
gtanzillo authored Apr 27, 2017
2 parents 6ddfbb6 + be284fe commit 5bc6bb6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/gems/pending/appliance_console/database_replication_standby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
22 changes: 22 additions & 0 deletions spec/appliance_console/database_replication_standby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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") }
Expand Down

0 comments on commit 5bc6bb6

Please sign in to comment.