engine: resources: Make some svc cleanups

We would often actually drop the refresh because of bad checks.
This commit is contained in:
James Shubin
2025-02-02 01:43:14 -05:00
parent 7439d532c7
commit 0fb546ad61

View File

@@ -255,23 +255,23 @@ func (obj *SvcRes) Watch(ctx context.Context) error {
switch event[svc].ActiveState { switch event[svc].ActiveState {
case "active": case "active":
obj.init.Logf("started") obj.init.Logf("event: started")
case "inactive": case "inactive":
obj.init.Logf("stopped") obj.init.Logf("event: stopped")
case "reloading": case "reloading":
obj.init.Logf("reloading") obj.init.Logf("event: reloading")
case "failed": case "failed":
obj.init.Logf("failed") obj.init.Logf("event: failed")
case "activating": case "activating":
obj.init.Logf("activating") obj.init.Logf("event: activating")
case "deactivating": case "deactivating":
obj.init.Logf("deactivating") obj.init.Logf("event: deactivating")
default: default:
return fmt.Errorf("unknown svc state: %s", event[svc].ActiveState) return fmt.Errorf("unknown svc state: %s", event[svc].ActiveState)
} }
} else { } else {
// svc stopped (and ActiveState is nil...) // svc stopped (and ActiveState is nil...)
obj.init.Logf("stopped") obj.init.Logf("event: stopped")
} }
send = true send = true
@@ -370,6 +370,7 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
result := make(chan string, 1) // catch result information result := make(chan string, 1) // catch result information
var status string var status string
if !stateOK {
if obj.State == "running" { if obj.State == "running" {
_, err = conn.StartUnitContext(ctx, svc, SystemdUnitModeFail, result) _, err = conn.StartUnitContext(ctx, svc, SystemdUnitModeFail, result)
} else if obj.State == "stopped" { } else if obj.State == "stopped" {
@@ -379,7 +380,7 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
return false, errwrap.Wrapf(err, "unable to change running status") return false, errwrap.Wrapf(err, "unable to change running status")
} }
if refresh { if refresh {
obj.init.Logf("Skipping reload, due to pending start/stop") obj.init.Logf("skipping reload, due to pending start/stop")
} }
refresh = false // We did a start or stop, so a reload is not needed. refresh = false // We did a start or stop, so a reload is not needed.
@@ -400,6 +401,7 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
default: default:
return false, fmt.Errorf("unknown systemd return string: %v", status) return false, fmt.Errorf("unknown systemd return string: %v", status)
} }
}
// XXX: also set enabled on boot // XXX: also set enabled on boot
@@ -407,7 +409,7 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
return false, nil // success return false, nil // success
} }
obj.init.Logf("Reloading...") obj.init.Logf("reloading...")
// From: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html // From: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html
// If a service is restarted that isn't running, it will be started // If a service is restarted that isn't running, it will be started