mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-23 14:06:18 +01:00
remove stale systemd services from tracking after deletion (#1594)
This commit is contained in:
@@ -144,13 +144,27 @@ func (sm *systemdManager) getServiceStats(conn *dbus.Conn, refresh bool) []*syst
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Track which units are currently present to remove stale entries
|
||||||
|
currentUnits := make(map[string]struct{}, len(units))
|
||||||
|
|
||||||
for _, unit := range units {
|
for _, unit := range units {
|
||||||
|
currentUnits[unit.Name] = struct{}{}
|
||||||
service, err := sm.updateServiceStats(conn, unit)
|
service, err := sm.updateServiceStats(conn, unit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
services = append(services, service)
|
services = append(services, service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove services that no longer exist in systemd
|
||||||
|
sm.Lock()
|
||||||
|
for unitName := range sm.serviceStatsMap {
|
||||||
|
if _, exists := currentUnits[unitName]; !exists {
|
||||||
|
delete(sm.serviceStatsMap, unitName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sm.Unlock()
|
||||||
|
|
||||||
sm.hasFreshStats = true
|
sm.hasFreshStats = true
|
||||||
return services
|
return services
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user