-
Notifications
You must be signed in to change notification settings - Fork 683
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
Use systemctl's helper command to determine enabled & active status #863
Conversation
Doing some manual testing of this until I can fix up some of the test environments. |
|
@stevendanna Can you explain, why the information we retrieve from systemd is not enough? This PR would introduce more commands. |
546b5e6
to
9403011
Compare
The output of `systemctl show SERVICENAME` can be misleading in the case of non-native services (i.e. services configured via an init script and integrated with systemd via a shim) or for more sophisticated unit types. For example, the UnitFileState of ntp is "bad": > systemctl show ntp | grep UnitFileState UnitFileState=bad despite systemd reporting it as enabled: > systemctl is-enabled ntp ntp.service is not a native service, redirecting to systemd-sysv-install Executing /lib/systemd/systemd-sysv-install is-enabled ntp enabled Further, the old parsing code would have missed unit files in the following states that are technically enabled: enabled-runtime, indirect, generated, and transient Using the `is-enabled` commands ensures that we report the same enabled status that systemd reports, without having to update our own parsing in the event that new unit states are added. Additionally, as shown above, it handles the sysv compatibility helper. Similarly, the is-active helper command ensures that we always report the same active/not-active status as systemd would natively. For instance, a quick reading of `src/systemctl/systemctl.c` in the systemd source shows that systemctl reports units as active if they are in the state `UNIT_ACTIVE` or `UNIT_RELOADING`. Fixes #749 Signed-off-by: Steven Danna <steve@chef.io>
9403011
to
28946f5
Compare
@chris-rock Added a comment with some justification of moving to the helper commands. Let me know your thoughts. I agree having to run 3 commands to get the status of a service is a big downside. The alternative is to add a bit more sophisticated handling that replicates what systemctl does. In the past systemd was moving more quickly, but given that new unit states haven't been added in some time, perhaps it wouldn't be that bad. |
We discussed that it is more stable to call systemd for enabled and running, to ensure we are not missing any edge-case. We take into account that this adds some additional calls, but since they are fast we decided not to do the effort to replicate systemd behavior. Thanks @stevendanna for the great discussion! |
Comments from an in-person discussion:
None of these tasks are hard individually, but together it would be nice to have some of the testing improvements (#861 and #862) in place before we do it. |
The output of
systemctl show SERVICENAME
can be misleading in thecase of non-native services (i.e. services configured via an init script
and integrated with systemd via a shim) or for more sophisticated unit
types.
For example, the UnitFileState of ntp is "bad":
despite systemd reporting it as enabled:
Further, the old parsing code would have missed unit files in the
following states that are technically enabled:
enabled-runtime, indirect, generated, and transient
Using the
is-enabled
commands ensures that we report the same enabledstatus that systemd reports, without having to update our own parsing in
the event that new unit states are added. Additionally, as shown above,
it handles the sysv compatibility helper.
Similarly, the is-active helper command ensures that we always report
the same active/not-active status as systemd would natively. For
instance, a quick reading of
src/systemctl/systemctl.c
in the systemdsource shows that systemctl reports units as active if they are in the
state
UNIT_ACTIVE
orUNIT_RELOADING
.Fixes #749
Signed-off-by: Steven Danna steve@chef.io