Skip to content

Conversation

@bastelfreak
Copy link
Collaborator

@bastelfreak bastelfreak commented Dec 13, 2025

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. 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

Summary

Ensure the service detection works with all locales.

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

Mention any related issues or pull requests.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

@bastelfreak bastelfreak self-assigned this Dec 13, 2025
bastelfreak added a commit to bastelfreak/puppet-foreman that referenced this pull request Dec 13, 2025
`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
the puppetlabs/postgresql CI still tests on Puppet 7. yumrepo_core
v3.0.0 doesn't support it anymore.
bastelfreak added a commit to theforeman/puppet-foreman that referenced this pull request Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant