From 09c614d02824109ec2389c9d2648cc4b898d6260 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 13 Dec 2025 13:51:45 +0100 Subject: [PATCH 1/3] Replace systemctl `status` with systemctl `is-active` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `systemctl status $service` will output a bunch of text. Some of this text, depending on the locale, contains unicode characters: ``` ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled) Active: active (exited) since Wed 2025-09-24 21:40:00 UTC; 2 months 18 days ago Main PID: 1028 (code=exited, status=0/SUCCESS) CPU: 3ms Notice: journal has been rotated since unit was started, output may be incomplete. ``` `●` is unicode. Puppet will fail with: ``` Error: /Stage[main]/Postgresql::Server::Reload/Postgresql::Server::Instance::Reload[main]/Exec[postgresql_reload_main]: Failed to call refresh: invalid byte sequence in US-ASCII Error: /Stage[main]/Postgresql::Server::Reload/Postgresql::Server::Instance::Reload[main]/Exec[postgresql_reload_main]: invalid byte sequence in US-ASCII ``` `systemctl` will print `*` if it's executed with `LC_ALL=C`, but we cannot assume that this locale is always used. The correct command to check if a service is up and running is `is-active`, not `status`. `status` is for humans only. the systemd provider for the service type also uses `is-active`. See https://github.com/puppetlabs/puppet/blob/main/lib/puppet/provider/service/systemd.rb#L201-L203 Since we only care about the exit code, we can even add `--quiet`. See https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#is-active%20PATTERN%E2%80%A6 --- manifests/params.pp | 10 +++++----- manifests/server.pp | 2 +- spec/acceptance/server_instance_spec.rb | 2 +- spec/classes/server/service_spec.rb | 2 +- spec/defines/server_instance_spec.rb | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 55dcd24c0f..41308acc8f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -86,7 +86,7 @@ } $service_reload = "systemctl reload ${service_name}" - $service_status = pick($service_status, "systemctl status ${service_name}") + $service_status = pick($service_status, "systemctl is-active --quiet ${service_name}") $psql_path = pick($psql_path, "${bindir}/psql") @@ -130,7 +130,7 @@ $confdir = pick($confdir, $datadir) $psql_path = pick($psql_path, "${bindir}/psql") - $service_status = pick($service_status, "systemctl status ${service_name}") + $service_status = pick($service_status, "systemctl is-active --quiet ${service_name}") $service_reload = "systemctl reload ${service_name}" $python_package_name = pick($python_package_name, 'python-psycopg2') # Archlinux does not have a perl::DBD::Pg package @@ -173,7 +173,7 @@ $datadir = pick($datadir, "/var/lib/postgresql/${version}/main") $confdir = pick($confdir, "/etc/postgresql/${version}/main") $service_reload = "systemctl reload ${service_name}" - $service_status = pick($service_status, "systemctl status ${service_name}") + $service_status = pick($service_status, "systemctl is-active --quiet ${service_name}") $psql_path = pick($psql_path, '/usr/bin/psql') $postgresql_conf_mode = pick($postgresql_conf_mode, '0644') } @@ -194,7 +194,7 @@ $bindir = pick($bindir, "/usr/lib/postgresql-${version}/bin") $datadir = pick($datadir, "/var/lib/postgresql/${version}_data") $confdir = pick($confdir, "/etc/postgresql-${version}") - $service_status = pick($service_status, "systemctl status ${service_name}") + $service_status = pick($service_status, "systemctl is-active --quiet ${service_name}") $service_reload = "systemctl reload ${service_name}" $psql_path = pick($psql_path, "${bindir}/psql") @@ -267,7 +267,7 @@ $bindir = pick($bindir, "/usr/lib/postgresql${version}/bin") $datadir = pick($datadir, '/var/lib/pgsql/data') $confdir = pick($confdir, $datadir) - $service_status = pick($service_status, "systemctl status ${service_name}") + $service_status = pick($service_status, "systemctl is-active --quiet ${service_name}") $service_reload = "systemctl reload ${service_name}" $psql_path = pick($psql_path, "${bindir}/psql") diff --git a/manifests/server.pp b/manifests/server.pp index 2516e43611..24ff268770 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -130,7 +130,7 @@ Boolean $service_restart_on_change = $postgresql::params::service_restart_on_change, Optional[String[1]] $service_provider = $postgresql::params::service_provider, String[1] $service_reload = $postgresql::params::service_reload, - Optional[String[1]] $service_status = $postgresql::params::service_status, + Optional[Variant[Array[String[1]],String[1]]] $service_status = $postgresql::params::service_status, String[1] $default_database = $postgresql::params::default_database, Hash $default_connect_settings = $postgresql::globals::default_connect_settings, Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::params::listen_addresses, diff --git a/spec/acceptance/server_instance_spec.rb b/spec/acceptance/server_instance_spec.rb index 4b8d6a4bb8..2d22981549 100644 --- a/spec/acceptance/server_instance_spec.rb +++ b/spec/acceptance/server_instance_spec.rb @@ -46,7 +46,7 @@ class { 'postgresql::server': }, service_settings => { 'service_name' => 'postgresql@13-test1', - 'service_status' => 'systemctl status postgresql@13-test1.service', + 'service_status' => 'systemctl is-active --quiet postgresql@13-test1.service', 'service_ensure' => 'running', 'service_enable' => true, }, diff --git a/spec/classes/server/service_spec.rb b/spec/classes/server/service_spec.rb index 1018fbc688..7c308250bb 100644 --- a/spec/classes/server/service_spec.rb +++ b/spec/classes/server/service_spec.rb @@ -10,5 +10,5 @@ end it { is_expected.to contain_class('postgresql::server::service') } - it { is_expected.to contain_service('postgresqld_instance_main').with_name('postgresql').with_status('systemctl status postgresql') } + it { is_expected.to contain_service('postgresqld_instance_main').with_name('postgresql').with_status('systemctl is-active --quiet postgresql') } end diff --git a/spec/defines/server_instance_spec.rb b/spec/defines/server_instance_spec.rb index ea63146fe4..43c018d744 100644 --- a/spec/defines/server_instance_spec.rb +++ b/spec/defines/server_instance_spec.rb @@ -42,7 +42,7 @@ class { 'postgresql::server': 'port' => 5433, 'pg_hba_conf_defaults' => false }, 'service_settings': { 'service_name' => 'postgresql@13-test1', - 'service_status' => 'systemctl status postgresql@13-test1.service', + 'service_status' => 'systemctl is-active --quiet postgresql@13-test1.service', 'service_ensure' => 'running', 'service_enable' => true }, 'initdb_settings': { 'auth_local' => 'peer', @@ -120,7 +120,7 @@ class { 'postgresql::server': it { is_expected.to contain_postgresql__server_instance('test1') } it { is_expected.to contain_user('ins_test1') } it { is_expected.to contain_group('ins_test1') } - it { is_expected.to contain_service('postgresqld_instance_test1').with_name('postgresql@13-test1').with_status('systemctl status postgresql@13-test1.service') } + it { is_expected.to contain_service('postgresqld_instance_test1').with_name('postgresql@13-test1').with_status('systemctl is-active --quiet postgresql@13-test1.service') } it { is_expected.to contain_systemd__dropin_file('postgresql@13-test1.conf') } it { is_expected.to contain_postgresql_conn_validator('validate_service_is_running_instance_test1') } it { is_expected.to contain_postgresql_conf('port_for_instance_test1') } From cd7b0eb5ae13aae4884a83ba3b74434a5ba1cad8 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 13 Dec 2025 14:14:48 +0100 Subject: [PATCH 2/3] .fixtures.yml: pin yumrepo_core to v2.1.0 the puppetlabs/postgresql CI still tests on Puppet 7. yumrepo_core v3.0.0 doesn't support it anymore. --- .fixtures.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index fbee13667e..7baa76231d 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -10,5 +10,7 @@ fixtures: provision: "https://github.com/puppetlabs/provision.git" puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" - yumrepo_core: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git" + yumrepo_core: + repo: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git" + ref: "v2.1.0" systemd: "https://github.com/voxpupuli/puppet-systemd.git" From 04d1909686fb57a447bc8bd6a0a70c1719d28f82 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 13 Dec 2025 14:18:30 +0100 Subject: [PATCH 3/3] .fixtures.yml: pin cron_core to v1.3.0 --- .fixtures.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index 7baa76231d..490615ba52 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,7 +4,9 @@ fixtures: apt: "https://github.com/puppetlabs/puppetlabs-apt.git" augeas_core: "https://github.com/puppetlabs/puppetlabs-augeas_core.git" concat: "https://github.com/puppetlabs/puppetlabs-concat.git" - cron_core: "https://github.com/puppetlabs/puppetlabs-cron_core.git" + cron_core: + repo: "https://github.com/puppetlabs/puppetlabs-cron_core.git" + ref: "v1.3.0" facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' firewall: "https://github.com/puppetlabs/puppetlabs-firewall.git" provision: "https://github.com/puppetlabs/provision.git"