Skip to content

Commit 7e91765

Browse files
authoredApr 25, 2024
Merge pull request #1588 from SimonHoenscheid/fix_instance_reload
Fix instance reload
2 parents 5e6e994 + e51f3d9 commit 7e91765

File tree

11 files changed

+40
-21
lines changed

11 files changed

+40
-21
lines changed
 

‎manifests/server/config_entry.pp

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# @param value Defines the value for the setting.
66
# @param path Path for postgresql.conf
77
# @param comment Defines the comment for the setting. The # is added by default.
8+
# @param instance_name The name of the instance.
89
#
910
define postgresql::server::config_entry (
1011
Enum['present', 'absent'] $ensure = 'present',
1112
String[1] $key = $name,
1213
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
1314
Stdlib::Absolutepath $path = $postgresql::server::postgresql_conf_path,
1415
Optional[String[1]] $comment = undef,
16+
String[1] $instance_name = 'main',
1517
) {
1618
# Those are the variables that are marked as "(change requires restart)"
1719
# on postgresql.conf. Items are ordered as on postgresql.conf.
@@ -72,15 +74,15 @@
7274
versioncmp($postgresql::server::_version, $requires_restart_until[$key]) < 0
7375
)) {
7476
Postgresql_conf {
75-
notify => Class['postgresql::server::reload'],
77+
notify => Postgresql::Server::Instance::Reload[$instance_name],
7678
}
7779
} elsif $postgresql::server::service_restart_on_change {
7880
Postgresql_conf {
79-
notify => Class['postgresql::server::service'],
81+
notify => Postgresql::Server::Instance::Service[$instance_name],
8082
}
8183
} else {
8284
Postgresql_conf {
83-
before => Class['postgresql::server::service'],
85+
before => Postgresql::Server::Instance::Service[$instance_name],
8486
}
8587
}
8688

@@ -90,6 +92,6 @@
9092
key => $key,
9193
value => $value,
9294
comment => $comment,
93-
require => Class['postgresql::server::initdb'],
95+
require => Postgresql::Server::Instance::Initdb[$instance_name],
9496
}
9597
}

‎manifests/server/database.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
postgresql_psql { "CREATE DATABASE \"${dbname}\"":
7373
command => "CREATE DATABASE \"${dbname}\" WITH ${template_option} ${encoding_option} ${locale_option} ${tablespace_option}",
7474
unless => "SELECT 1 FROM pg_database WHERE datname = '${dbname}'",
75-
require => Class['postgresql::server::service'],
75+
require => Postgresql::Server::Instance::Service[$instance],
7676
}
7777

7878
# This will prevent users from connecting to the database unless they've been

‎manifests/server/database_grant.pp

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# @param psql_group Overrides the default postgres user group to be used for related files in the file system.
1010
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1111
# @param port Port to use when connecting.
12+
# @param instance The name of the Postgresql database instance.
1213
define postgresql::server::database_grant (
1314
Enum['ALL', 'CREATE', 'CONNECT', 'TEMPORARY', 'TEMP', 'all', 'create', 'connect', 'temporary', 'temp'] $privilege,
1415
String[1] $db,
@@ -19,6 +20,7 @@
1920
Hash $connect_settings = $postgresql::server::default_connect_settings,
2021
String[1] $psql_group = $postgresql::server::group,
2122
Stdlib::Port $port = $postgresql::server::port,
23+
String[1] $instance = 'main',
2224
) {
2325
postgresql::server::grant { "database:${name}":
2426
ensure => $ensure,
@@ -32,5 +34,6 @@
3234
group => $psql_group,
3335
port => $port,
3436
connect_settings => $connect_settings,
37+
instance => $instance,
3538
}
3639
}

‎manifests/server/db.pp

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
port => $port,
4545
user => $psql_user,
4646
group => $psql_group,
47+
instance => $instance,
4748
}
4849
}
4950

@@ -54,6 +55,7 @@
5455
psql_user => $psql_user,
5556
psql_group => $psql_group,
5657
before => Postgresql::Server::Database[$dbname],
58+
instance => $instance,
5759
}
5860
}
5961

@@ -65,6 +67,7 @@
6567
port => $port,
6668
psql_user => $psql_user,
6769
psql_group => $psql_group,
70+
instance => $instance,
6871
} -> Postgresql_conn_validator<| db_name == $dbname |>
6972
}
7073

‎manifests/server/instance/config.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
group => $group,
8989
mode => '0640',
9090
warn => true,
91-
notify => Class['postgresql::server::reload'],
91+
notify => Postgresql::Server::Instance::Reload[$name],
9292
}
9393

9494
if $pg_hba_conf_defaults {
@@ -249,7 +249,7 @@
249249
group => $group,
250250
mode => '0640',
251251
warn => true,
252-
notify => Class['postgresql::server::reload'],
252+
notify => Postgresql::Server::Instance::Reload[$name],
253253
}
254254
}
255255

‎manifests/server/instance/reload.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
command => $service_reload,
1212
onlyif => $service_status,
1313
refreshonly => true,
14-
require => Class['postgresql::server::service'],
14+
require => Postgresql::Server::Instance::Service[$name],
1515
}
1616
}

‎manifests/server/instance/systemd.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
extra_systemd_config => $extra_systemd_config,
3333
}
3434
),
35-
notify => Class['postgresql::server::service'],
36-
before => Class['postgresql::server::reload'],
35+
notify => Postgresql::Server::Instance::Service[$name],
36+
before => Postgresql::Server::Instance::Reload[$name],
3737
}
3838
}
3939
}

‎manifests/server/table_grant.pp

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# @param psql_user Specifies the OS user for running psql.
1313
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
1414
# @param onlyif_exists Create grant only if it doesn't exist.
15+
# @param instance The name of the Postgresql database instance.
1516
define postgresql::server::table_grant (
1617
Enum['ALL', 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER', 'all', 'select', 'insert', 'update', 'delete',
1718
'truncate', 'references', 'trigger'] $privilege,
@@ -24,6 +25,7 @@
2425
Optional[String[1]] $psql_user = undef,
2526
Optional[Hash] $connect_settings = undef,
2627
Boolean $onlyif_exists = false,
28+
String[1] $instance = 'main',
2729
) {
2830
postgresql::server::grant { "table:${name}":
2931
ensure => $ensure,
@@ -37,5 +39,6 @@
3739
psql_user => $psql_user,
3840
onlyif_exists => $onlyif_exists,
3941
connect_settings => $connect_settings,
42+
instance => $instance,
4043
}
4144
}

‎manifests/server_instance.pp

+17-9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
port => $config_settings['port'],
6767
user => $instance_user,
6868
}
69+
postgresql::server::instance::reload { $instance_name:
70+
service_status => $service_settings['service_status'],
71+
service_reload => "systemctl reload ${service_settings['service_name']}.service",
72+
}
6973
postgresql::server::instance::passwd { $instance_name:
7074
* => $passwd_settings,
7175
}
@@ -84,11 +88,12 @@
8488
$value = $settings['value']
8589
$comment = $settings['comment']
8690
postgresql::server::config_entry { "${entry}_${$instance_name}":
87-
ensure => bool2str($value =~ Undef, 'absent', 'present'),
88-
key => $entry,
89-
value => $value,
90-
comment => $comment,
91-
path => $config_settings['postgresql_conf_path'],
91+
ensure => bool2str($value =~ Undef, 'absent', 'present'),
92+
key => $entry,
93+
value => $value,
94+
comment => $comment,
95+
path => $config_settings['postgresql_conf_path'],
96+
instance_name => $instance_name,
9297
}
9398
}
9499
$pg_hba_rules.each |String[1] $rule_name, Postgresql::Pg_hba_rule $rule| {
@@ -108,10 +113,11 @@
108113
}
109114
$databases.each |$database, $database_details| {
110115
postgresql::server::database { $database:
111-
* => $database_details,
112-
user => $instance_user,
113-
group => $instance_group,
114-
port => $config_settings['port'],
116+
* => $database_details,
117+
user => $instance_user,
118+
group => $instance_group,
119+
port => $config_settings['port'],
120+
instance => $instance_name,
115121
}
116122
}
117123
$database_grants.each |$db_grant_title, $dbgrants| {
@@ -120,13 +126,15 @@
120126
psql_user => $instance_user,
121127
psql_group => $instance_group,
122128
port => $config_settings['port'],
129+
instance => $instance_name,
123130
}
124131
}
125132
$table_grants.each |$table_grant_title, $tgrants| {
126133
postgresql::server::table_grant { $table_grant_title:
127134
* => $tgrants,
128135
psql_user => $instance_user,
129136
port => $config_settings['port'],
137+
instance => $instance_name,
130138
}
131139
}
132140
}

‎spec/classes/server_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class { 'postgresql::globals':
129129
it { is_expected.to contain_class('postgresql::server') }
130130

131131
it {
132-
expect(subject).to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Class[postgresql::server::service]')
132+
expect(subject).to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Postgresql::Server::Instance::Service[main]')
133133
}
134134

135135
it { is_expected.to contain_postgresql__server__config_entry('data_directory_for_instance_main') }

‎spec/defines/server/config_entry_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
expect(subject).to contain_postgresql_conf('unix_socket_directories')
7777
.with(name: 'unix_socket_directories',
7878
value: '/var/pgsql, /opt/postgresql, /root/')
79-
.that_notifies('Class[postgresql::server::service]')
79+
.that_notifies('Postgresql::Server::Instance::Service[main]')
8080
end
8181
end
8282
end

0 commit comments

Comments
 (0)