Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

sentinel: remove a forwarder service that never started

shukieshah34aac9271508
diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder.go b/cli/beacon/internal/endpoint/sentinel/forwarder.go
index f79afd73..1e287130 100644
--- a/cli/beacon/internal/endpoint/sentinel/forwarder.go
+++ b/cli/beacon/internal/endpoint/sentinel/forwarder.go
@@ -418,7 +418,11 @@ func Install(o InstallOptions) (InstallResult, error) {
return InstallResult{}, err
}
if err := manager.Load(); err != nil {
- return InstallResult{}, fmt.Errorf("%w; Vector's own log is in %s", err, logDir)
+ // A Vector that never reached running is removed rather than left hanging, registered and
+ // holding its binary. The settings stay, so fixing the cause and installing again, or the
+ // next repair or upgrade, brings it back.
+ _ = manager.Unload()
+ return InstallResult{}, fmt.Errorf("%w; the service was removed, and Vector's own log is in %s", err, logDir)
}
return InstallResult{Dir: dir, Config: configPath, Unit: unit, Vector: vector.Path, Service: manager.Status()}, nil
}
diff --git a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go b/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
index ac3c9048..023e69ac 100644
--- a/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
+++ b/cli/beacon/internal/endpoint/sentinel/forwarder_test.go
@@ -18,6 +18,7 @@ import (
type fakeService struct {
spec service.ForwarderSpec
unsupported string
+ loadErr error
units []string
loads int
unloads int
@@ -34,9 +35,16 @@ func (f *fakeService) WriteUnit(vectorBin, configPath string) (string, error) {
return "unit:" + f.spec.Label, nil
}
func (f *fakeService) UnitCurrent(string, string) (bool, error) { return f.current, nil }
-func (f *fakeService) Load() error { f.loads++; f.running = true; return nil }
-func (f *fakeService) Unload() error { f.unloads++; f.running = false; return nil }
-func (f *fakeService) RemoveUnits() { f.removed++ }
+func (f *fakeService) Load() error {
+ f.loads++
+ if f.loadErr != nil {
+ return f.loadErr
+ }
+ f.running = true
+ return nil
+}
+func (f *fakeService) Unload() error { f.unloads++; f.running = false; return nil }
+func (f *fakeService) RemoveUnits() { f.removed++ }
func (f *fakeService) Status() service.Status {
return service.Status{Label: f.spec.Label, Loaded: f.running, Running: f.running}
}
@@ -365,3 +373,18 @@ func TestManualVectorConfigKeepsItsEnvironmentContract(t *testing.T) {
}
}
}
+
+// A Vector that never reaches running is removed, not left hanging with its binary locked.
+func TestForwarderInstallRemovesAServiceThatNeverStarted(t *testing.T) {
+ f := newForwarderFixture(t)
+ f.svc.loadErr = errors.New("the BeaconSentinelForwarder service is still starting after 1m0s")
+ if _, err := Install(validInstall()); err == nil || !strings.Contains(err.Error(), "removed") {
+ t.Fatalf("Install: %v", err)
+ }
+ if f.svc.unloads != 1 {
+ t.Fatalf("unloads = %d, want the hung service removed", f.svc.unloads)
+ }
+ if _, err := ReadSettings(); err != nil {
+ t.Fatalf("the settings must stay for the next install or reconcile: %v", err)
+ }
+}