diff --git a/site-cookbooks/kosmos_postgresql/libraries/helpers.rb b/site-cookbooks/kosmos_postgresql/libraries/helpers.rb index 5de6e76..f87dda2 100644 --- a/site-cookbooks/kosmos_postgresql/libraries/helpers.rb +++ b/site-cookbooks/kosmos_postgresql/libraries/helpers.rb @@ -39,13 +39,5 @@ class Chef def postgresql_version node['kosmos_postgresql']['postgresql_version'] end - - def postgresql_service - "postgresql@#{postgresql_version}-main" - end - - def postgresql_data_dir - "/var/lib/postgresql/#{postgresql_version}/main" - end end end diff --git a/site-cookbooks/kosmos_postgresql/recipes/replica.rb b/site-cookbooks/kosmos_postgresql/recipes/replica.rb index 95a037a..7d355c4 100644 --- a/site-cookbooks/kosmos_postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos_postgresql/recipes/replica.rb @@ -16,16 +16,19 @@ if primary.nil? return end +postgresql_service_name = "postgresql@#{postgresql_version}-main" +postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main" + # TODO Replace pg.kosmos.local with private IP once available # via proper node attribute # https://gitea.kosmos.org/kosmos/chef/issues/263 execute "set up replication" do command <<-EOF -systemctl stop #{postgresql_service} +systemctl stop #{postgresql_service_name} mv #{postgresql_data_dir} #{postgresql_data_dir}.old pg_basebackup -h pg.kosmos.local -U replication -D #{postgresql_data_dir} -R chown -R postgres:postgres #{postgresql_data_dir} -systemctl start #{postgresql_service} +systemctl start #{postgresql_service_name} EOF environment 'PGPASSWORD' => postgresql_data_bag_item['replication_password'] sensitive true