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 Aug 21, 2023
1 parent 9ef5488 commit 788c06b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
16 changes: 6 additions & 10 deletions manifests/server/instance/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,11 @@
notify => Class['postgresql::server::reload'],
}
}
# lint:ignore:140chars
# RHEL 7 and 8 both support drop-in files for systemd units. Gentoo also supports drop-in files.
# Edit 02/2023 RHEL basedc Systems and Gentoo need Variables set for $PGPORT, $DATA_DIR or $PGDATA, thats what the drop-in file is for.
# lint:endignore:140chars
if $facts['os']['family'] in ['RedHat', '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,
}
}
48 changes: 31 additions & 17 deletions manifests/server/instance/systemd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,41 @@
define postgresql::server::instance::systemd (
Variant[String[1], Stdlib::Port] $port,
Stdlib::Absolutepath $datadir,
String[1] $service_name,
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 $instance_name == 'main' {
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'],
} else {
# instance systemd file here
}
}
}

0 comments on commit 788c06b

Please sign in to comment.