Skip to content

Commit 837517c

Browse files
committed
Replace systemctl status with systemctl is-active
`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. If puppet runs with the default LC_LANG=C, it will fail and raise: ``` 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 ``` 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
1 parent 029754c commit 837517c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

manifests/params.pp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
}
8787

8888
$service_reload = "systemctl reload ${service_name}"
89-
$service_status = pick($service_status, "systemctl status ${service_name}")
89+
$service_status = pick($service_status, "systemctl is-active ${service_name}")
9090

9191
$psql_path = pick($psql_path, "${bindir}/psql")
9292

@@ -130,7 +130,7 @@
130130
$confdir = pick($confdir, $datadir)
131131
$psql_path = pick($psql_path, "${bindir}/psql")
132132

133-
$service_status = pick($service_status, "systemctl status ${service_name}")
133+
$service_status = pick($service_status, "systemctl is-active ${service_name}")
134134
$service_reload = "systemctl reload ${service_name}"
135135
$python_package_name = pick($python_package_name, 'python-psycopg2')
136136
# Archlinux does not have a perl::DBD::Pg package
@@ -173,7 +173,7 @@
173173
$datadir = pick($datadir, "/var/lib/postgresql/${version}/main")
174174
$confdir = pick($confdir, "/etc/postgresql/${version}/main")
175175
$service_reload = "systemctl reload ${service_name}"
176-
$service_status = pick($service_status, "systemctl status ${service_name}")
176+
$service_status = pick($service_status, "systemctl is-active ${service_name}")
177177
$psql_path = pick($psql_path, '/usr/bin/psql')
178178
$postgresql_conf_mode = pick($postgresql_conf_mode, '0644')
179179
}
@@ -194,7 +194,7 @@
194194
$bindir = pick($bindir, "/usr/lib/postgresql-${version}/bin")
195195
$datadir = pick($datadir, "/var/lib/postgresql/${version}_data")
196196
$confdir = pick($confdir, "/etc/postgresql-${version}")
197-
$service_status = pick($service_status, "systemctl status ${service_name}")
197+
$service_status = pick($service_status, "systemctl is-active ${service_name}")
198198
$service_reload = "systemctl reload ${service_name}"
199199
$psql_path = pick($psql_path, "${bindir}/psql")
200200

@@ -267,7 +267,7 @@
267267
$bindir = pick($bindir, "/usr/lib/postgresql${version}/bin")
268268
$datadir = pick($datadir, '/var/lib/pgsql/data')
269269
$confdir = pick($confdir, $datadir)
270-
$service_status = pick($service_status, "systemctl status ${service_name}")
270+
$service_status = pick($service_status, "systemctl is-active ${service_name}")
271271
$service_reload = "systemctl reload ${service_name}"
272272
$psql_path = pick($psql_path, "${bindir}/psql")
273273

manifests/server.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
Boolean $service_restart_on_change = $postgresql::params::service_restart_on_change,
131131
Optional[String[1]] $service_provider = $postgresql::params::service_provider,
132132
String[1] $service_reload = $postgresql::params::service_reload,
133-
Optional[String[1]] $service_status = $postgresql::params::service_status,
133+
Optional[Variant[Array[String[1]],String[1]]] $service_status = $postgresql::params::service_status,
134134
String[1] $default_database = $postgresql::params::default_database,
135135
Hash $default_connect_settings = $postgresql::globals::default_connect_settings,
136136
Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::params::listen_addresses,

spec/acceptance/server_instance_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class { 'postgresql::server':
4646
},
4747
service_settings => {
4848
'service_name' => 'postgresql@13-test1',
49-
'service_status' => 'systemctl status [email protected]',
49+
'service_status' => 'systemctl is-active [email protected]',
5050
'service_ensure' => 'running',
5151
'service_enable' => true,
5252
},

spec/classes/server/service_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
end
1111

1212
it { is_expected.to contain_class('postgresql::server::service') }
13-
it { is_expected.to contain_service('postgresqld_instance_main').with_name('postgresql').with_status('systemctl status postgresql') }
13+
it { is_expected.to contain_service('postgresqld_instance_main').with_name('postgresql').with_status('systemctl is-active postgresql') }
1414
end

spec/defines/server_instance_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class { 'postgresql::server':
4242
'port' => 5433,
4343
'pg_hba_conf_defaults' => false },
4444
'service_settings': { 'service_name' => 'postgresql@13-test1',
45-
'service_status' => 'systemctl status [email protected]',
45+
'service_status' => 'systemctl is-active [email protected]',
4646
'service_ensure' => 'running',
4747
'service_enable' => true },
4848
'initdb_settings': { 'auth_local' => 'peer',
@@ -120,7 +120,7 @@ class { 'postgresql::server':
120120
it { is_expected.to contain_postgresql__server_instance('test1') }
121121
it { is_expected.to contain_user('ins_test1') }
122122
it { is_expected.to contain_group('ins_test1') }
123-
it { is_expected.to contain_service('postgresqld_instance_test1').with_name('postgresql@13-test1').with_status('systemctl status [email protected]') }
123+
it { is_expected.to contain_service('postgresqld_instance_test1').with_name('postgresql@13-test1').with_status('systemctl is-active [email protected]') }
124124
it { is_expected.to contain_systemd__dropin_file('[email protected]') }
125125
it { is_expected.to contain_postgresql_conn_validator('validate_service_is_running_instance_test1') }
126126
it { is_expected.to contain_postgresql_conf('port_for_instance_test1') }

0 commit comments

Comments
 (0)