Skip to content

Commit

Permalink
extend systemd define to handle instance systemd files
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHoenscheid committed Sep 27, 2023
1 parent 3152372 commit 5b829f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
13 changes: 6 additions & 7 deletions manifests/server/instance/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,11 @@
notify => Class['postgresql::server::reload'],
}
}
# RHEL based systems and Gentoo need variables set for $PGPORT, $DATA_DIR or $PGDATA via a drop-in file
if $facts['os']['family'] == 'RedHat' or ($facts['os']['family'] == 'Gentoo' and $facts['service_provider'] == 'systemd') {
postgresql::server::instance::systemd { $service_name:
port => $port,
datadir => $datadir,
extra_systemd_config => $extra_systemd_config,
}

postgresql::server::instance::systemd { $name:
port => $port,
datadir => $datadir,
extra_systemd_config => $extra_systemd_config,
service_name => $service_name,
}
}
42 changes: 26 additions & 16 deletions manifests/server/instance/systemd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@
define postgresql::server::instance::systemd (
Stdlib::Port $port,
Stdlib::Absolutepath $datadir,
String[1] $instance_name = $name,
Optional[String[1]] $extra_systemd_config = undef,
String[1] $service_name = $name,
Enum[present, absent] $drop_in_ensure = 'present',
) {
# Template uses:
# - $port
# - $datadir
# - $extra_systemd_config
systemd::dropin_file { "${service_name}.conf":
ensure => $drop_in_ensure,
unit => "${service_name}.service",
owner => 'root',
group => 'root',
content => epp('postgresql/systemd-override.conf.epp', {
port => $port,
datadir => $datadir,
extra_systemd_config => $extra_systemd_config,
if $facts['service_provider'] == 'systemd' {
if $facts['os']['family'] in ['RedHat', 'Gentoo'] {
# RHEL 7 and 8 both support drop-in files for systemd units.
# Gentoo also supports drop-in files.
# RHEL based Systems need Variables set for $PGPORT, $DATA_DIR or $PGDATA, thats what the drop-in file is for.
# For additional instances (!= 'main') we need a new systemd service anyhow and use one systemd-file. no dropin needed.
#
# Template uses:
# - $port
# - $datadir
# - $extra_systemd_config
systemd::dropin_file { "${service_name}.conf":
ensure => $drop_in_ensure,
unit => "${service_name}.service",
owner => 'root',
group => 'root',
content => epp('postgresql/systemd-override.conf.epp', {
port => $port,
datadir => $datadir,
extra_systemd_config => $extra_systemd_config,
}
),
notify => Class['postgresql::server::service'],
before => Class['postgresql::server::reload'],
}
),
notify => Class['postgresql::server::service'],
before => Class['postgresql::server::reload'],
}
}
}

0 comments on commit 5b829f4

Please sign in to comment.