Refactor postgres server recipes/resource
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
node.default['kosmos_postgresql']['postgresql_version'] = "14"
|
||||||
|
|
||||||
# This is set to false by default, and set to true in the server resource
|
# This is set to false by default, and set to true in the server resource
|
||||||
# for replicas.
|
# for replicas.
|
||||||
node.default['kosmos_postgresql']['ready_to_set_up_replica'] = false
|
node.default['kosmos_postgresql']['ready_to_set_up_replica'] = false
|
||||||
|
|
||||||
|
# Address space from which clients are allowed to connect
|
||||||
|
node.default['kosmos_postgresql']['access_addr'] = "10.1.1.0/24"
|
||||||
|
|||||||
@@ -36,10 +36,16 @@ class Chef
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def postgresql_service_name
|
def postgresql_version
|
||||||
postgresql_version = "12"
|
node['kosmos_postgresql']['postgresql_version']
|
||||||
|
end
|
||||||
|
|
||||||
|
def postgresql_service
|
||||||
"postgresql@#{postgresql_version}-main"
|
"postgresql@#{postgresql_version}-main"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def postgresql_data_dir
|
||||||
|
"/var/lib/postgresql/#{postgresql_version}/main"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,31 +3,7 @@
|
|||||||
# Recipe:: primary
|
# Recipe:: primary
|
||||||
#
|
#
|
||||||
|
|
||||||
postgresql_version = "12"
|
|
||||||
postgresql_service = "postgresql@#{postgresql_version}-main"
|
|
||||||
|
|
||||||
service postgresql_service do
|
|
||||||
supports restart: true, status: true, reload: true
|
|
||||||
end
|
|
||||||
|
|
||||||
postgresql_custom_server postgresql_version do
|
postgresql_custom_server postgresql_version do
|
||||||
role "primary"
|
role "primary"
|
||||||
end
|
end
|
||||||
|
|
||||||
postgresql_access "zerotier members" do
|
|
||||||
access_type "host"
|
|
||||||
access_db "all"
|
|
||||||
access_user "all"
|
|
||||||
access_addr "10.1.1.0/24"
|
|
||||||
access_method "md5"
|
|
||||||
notifies :reload, "service[#{postgresql_service}]", :immediately
|
|
||||||
end
|
|
||||||
|
|
||||||
postgresql_access "zerotier members replication" do
|
|
||||||
access_type "host"
|
|
||||||
access_db "replication"
|
|
||||||
access_user "replication"
|
|
||||||
access_addr "10.1.1.0/24"
|
|
||||||
access_method "md5"
|
|
||||||
notifies :reload, "service[#{postgresql_service}]", :immediately
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -3,26 +3,23 @@
|
|||||||
# Recipe:: replica
|
# Recipe:: replica
|
||||||
#
|
#
|
||||||
|
|
||||||
postgresql_version = "12"
|
service postgresql_service do
|
||||||
postgresql_service = "postgresql@#{postgresql_version}-main"
|
supports restart: true, status: true, reload: true
|
||||||
|
end
|
||||||
|
|
||||||
postgresql_custom_server postgresql_version do
|
postgresql_custom_server postgresql_version do
|
||||||
role "replica"
|
role "replica"
|
||||||
end
|
end
|
||||||
|
|
||||||
service postgresql_service do
|
|
||||||
supports restart: true, status: true, reload: true
|
|
||||||
end
|
|
||||||
|
|
||||||
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
||||||
|
|
||||||
primary = postgresql_primary
|
primary = postgresql_primary
|
||||||
|
|
||||||
unless primary.nil?
|
if primary.nil?
|
||||||
# TODO
|
Chef::Log.warn("No PostgreSQL primary node found. Skipping replication setup.")
|
||||||
postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main"
|
return
|
||||||
|
end
|
||||||
|
|
||||||
# FIXME get zerotier IP
|
|
||||||
execute "set up replication" do
|
execute "set up replication" do
|
||||||
command <<-EOF
|
command <<-EOF
|
||||||
systemctl stop #{postgresql_service}
|
systemctl stop #{postgresql_service}
|
||||||
@@ -35,22 +32,3 @@ systemctl start #{postgresql_service}
|
|||||||
sensitive true
|
sensitive true
|
||||||
not_if { ::File.exist? "#{postgresql_data_dir}/standby.signal" }
|
not_if { ::File.exist? "#{postgresql_data_dir}/standby.signal" }
|
||||||
end
|
end
|
||||||
|
|
||||||
postgresql_access "zerotier members" do
|
|
||||||
access_type "host"
|
|
||||||
access_db "all"
|
|
||||||
access_user "all"
|
|
||||||
access_addr "10.1.1.0/24"
|
|
||||||
access_method "md5"
|
|
||||||
notifies :reload, "service[#{postgresql_service}]", :immediately
|
|
||||||
end
|
|
||||||
|
|
||||||
postgresql_access "zerotier members replication" do
|
|
||||||
access_type "host"
|
|
||||||
access_db "replication"
|
|
||||||
access_user "replication"
|
|
||||||
access_addr "10.1.1.0/24"
|
|
||||||
access_method "md5"
|
|
||||||
notifies :reload, "service[#{postgresql_service}]", :immediately
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -70,6 +70,24 @@ action :create do
|
|||||||
replication true
|
replication true
|
||||||
password postgresql_credentials['replication_password']
|
password postgresql_credentials['replication_password']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
postgresql_access "all members" do
|
||||||
|
access_type "host"
|
||||||
|
access_db "all"
|
||||||
|
access_user "all"
|
||||||
|
access_addr node['kosmos_postgresql']['access_addr']
|
||||||
|
access_method "md5"
|
||||||
|
notifies :reload, "service[#{postgresql_service}]", :immediately
|
||||||
|
end
|
||||||
|
|
||||||
|
postgresql_access "replication members" do
|
||||||
|
access_type "host"
|
||||||
|
access_db "replication"
|
||||||
|
access_user "replication"
|
||||||
|
access_addr node['kosmos_postgresql']['access_addr']
|
||||||
|
access_method "md5"
|
||||||
|
notifies :reload, "service[#{postgresql_service}]", :immediately
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
action_class do
|
action_class do
|
||||||
|
|||||||
Reference in New Issue
Block a user