Replace systemctl status with systemctl is-active
#1652
+16
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)