Can cf-agent easily know about "systemd" state/target, etc.?

9 views
Skip to first unread message

t.d...@servicemusic.org.uk

unread,
Dec 5, 2024, 9:33:41 AM12/5/24
to help-cfengine
Context: Linux "systemd" machine; CFE 3.18.

We have an emerging use case to run a specific, minimal (i.e. fast) subset of our cf-agent policy during machine shutdown/halt.  We are considering a "systemd" service with something like:

    ExecStop=cf-agent....

Is there something already in place which can tell us the current state (target?) of systemd?  Perhaps a "var" (e.g. "sys.") in CFE?  Or perhaps something in "/proc" or similar that our policy could peek at?

Failing that, we do could something like:

    ExecStop=cf-agent ... -D HALTING

Thanks.

-- David Lee
-- Diamond Light Source

Nick Anderson

unread,
Dec 5, 2024, 1:33:28 PM12/5/24
to help-cfengine

Context: Linux "systemd" machine; CFE 3.18.

We have an emerging use case to run a specific, minimal (i.e. fast) subset of our cf-agent policy during machine shutdown/halt. We are considering a "systemd" service with something like:

ExecStop=cf-agent….

Is there something already in place which can tell us the current state (target?) of systemd? Perhaps a "var" (e.g. "sys.") in CFE? Or perhaps something in "/proc" or similar that our policy could peek at?

There aren't any system variables that hold states of systemd units and I am not familiar with anything in proc that indicates a systemd unit state.

bundle agent systemd_services which is used to manage systemd service state parses information returned by systemctl --no-ask-password --global --system -pLoadState,CanStop,UnitFileState,ActiveState,LoadState,CanStart,CanReload show <service>

https://github.com/cfengine/masterfiles/blob/b91ca88286d8efece4050e9e4811e801b408d034/lib/services.cf#L370-L380

Failing that, we do could something like:

ExecStop=cf-agent … -D HALTING

Seems like a reasonable thing to try.

t.d...@servicemusic.org.uk

unread,
Dec 5, 2024, 1:58:19 PM12/5/24
to help-cfengine
Thanks, Nick. That gives us a good direction to explore.

-- David Lee
Reply all
Reply to author
Forward
0 new messages