From b5384d127834acd3676f40cb72ffdcfebb021c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louren=C3=A7o?= <133565059+lourencovales@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:47:12 +0100 Subject: [PATCH] engine: resources: Adding logic for svc unit state This is a small patch that adds logic for checking what's the state of the unit file and making the CheckApply function more robust --- engine/resources/svc.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/resources/svc.go b/engine/resources/svc.go index 3186149c..0c28bb18 100644 --- a/engine/resources/svc.go +++ b/engine/resources/svc.go @@ -333,7 +333,15 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) { var running = (activestate.Value == dbus.MakeVariant("active")) var stateOK = ((obj.State == "") || (obj.State == "running" && running) || (obj.State == "stopped" && !running)) - var startupOK = true // XXX: DETECT AND SET + + startupstate, err := conn.GetUnitPropertyContext(ctx, svc, "UnitFileState") + if err != nil { + return false, errwrap.Wrapf(err, "failed to get unit file state") + } + + enabled := (startupstate.Value == dbus.MakeVariant("enabled")) + disabled := (startupstate.Value == dbus.MakeVariant("disabled")) + startupOK := ((obj.Startup == "") || (obj.Startup == "enabled" && enabled) || (obj.Startup == "disabled" && disabled)) // NOTE: if this svc resource is embedded as a composite resource inside // of another resource using a technique such as `makeComposite()`, then