-
Notifications
You must be signed in to change notification settings - Fork 612
Replace systemctl status with systemctl is-active
#1652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`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.
smortex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Not sure if we should have the last 2 commits merged, but the first one is definitively needed!
|
Yeah, I hope someone fixes the CI and removes the puppet 7 checks soon :( |
I was thinking about clicking the merge button to unbreak the module… Tests are not mandatory for brave people |
Replace systemctl
statuswith systemctlis-activesystemctl status $servicewill output a bunch of text. Some of this text, depending on the locale, contains unicode characters:●is unicode. Puppet will fail with:systemctlwill print*if it's executed withLC_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, notstatus.statusis for humans only. the systemd provider for the service type also usesis-active. See https://github.com/puppetlabs/puppet/blob/main/lib/puppet/provider/service/systemd.rb#L201-L203Since 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%A6Summary
Ensure the service detection works with all locales.
Additional Context
Add any additional context about the problem here.
Related Issues (if any)
Mention any related issues or pull requests.
Checklist
puppet apply)