Discussion:
systemctl is-active command returns inactive even if the unit does not exist
(too old to reply)
Kevin Hsu
2018-01-25 05:43:29 UTC
Permalink
Raw Message
Hi folks,

"systemctl is-active" command gives "inactive" no matter the unit exists
and indeed inactive or it just not exist. This behavior is semantically
true since a unit can never be active
if it does not exist. But "systemctl is-enabled" command will give a clear
result "Failed to get unit file state for no-exist.service: No such file or
directory" to indicate user the existence
of the given unit. I am wondering if "systemctl is-active" should behave
the same.


systemctl --version

systemd 235


systemctl is-active non-exist.service

inactive

systemctl is-enabled non-exist.service
Failed to get unit file state for non-exist.service: No such file or
directory

Best regards,
Kevin Hsu
Michael Chapman
2018-01-25 07:06:46 UTC
Permalink
Raw Message
Post by Kevin Hsu
Hi folks,
"systemctl is-active" command gives "inactive" no matter the unit exists
and indeed inactive or it just not exist. This behavior is semantically
true since a unit can never be active
if it does not exist. But "systemctl is-enabled" command will give a clear
result "Failed to get unit file state for no-exist.service: No such file or
directory" to indicate user the existence
of the given unit. I am wondering if "systemctl is-active" should behave
the same.
I don't think it would be possible to change what "systemctl is-active"
prints out now, and I think it makes sense for it to track the ActiveState
property of the unit precisely.

You can get the properties of a unit using "systemctl show". For example:

$ systemctl show --property LoadState,ActiveState,SubState \
does-not-exist.service
LoadState=not-found
ActiveState=inactive
SubState=dead

As you can see here, what you're interested in is the "load state" of the
unit, which is somewhat orthogonal to the unit's "active state".

Loading...