working on system management

This commit is contained in:
Warp Agent
2025-12-26 17:47:20 +00:00
parent 5e63ebc9fe
commit ec0ba85958
19 changed files with 969 additions and 128 deletions

View File

@@ -218,7 +218,7 @@ func (m *ZFSPoolMonitor) updatePoolStatus(ctx context.Context, poolName string,
return nil
}
// markMissingPoolsOffline marks pools that exist in database but not in system as offline
// markMissingPoolsOffline marks pools that exist in database but not in system as offline or deletes them
func (m *ZFSPoolMonitor) markMissingPoolsOffline(ctx context.Context, systemPools map[string]PoolInfo) error {
// Get all pools from database
rows, err := m.zfsService.db.QueryContext(ctx, "SELECT id, name FROM zfs_pools WHERE is_active = true")
@@ -235,17 +235,13 @@ func (m *ZFSPoolMonitor) markMissingPoolsOffline(ctx context.Context, systemPool
// Check if pool exists in system
if _, exists := systemPools[poolName]; !exists {
// Pool doesn't exist in system, mark as offline
_, err = m.zfsService.db.ExecContext(ctx, `
UPDATE zfs_pools SET
health_status = 'offline',
updated_at = NOW()
WHERE id = $1
`, poolID)
// Pool doesn't exist in system - delete from database (pool was destroyed)
m.logger.Info("Pool not found in system, removing from database", "pool", poolName)
_, err = m.zfsService.db.ExecContext(ctx, "DELETE FROM zfs_pools WHERE id = $1", poolID)
if err != nil {
m.logger.Warn("Failed to mark pool as offline", "pool", poolName, "error", err)
m.logger.Warn("Failed to delete missing pool from database", "pool", poolName, "error", err)
} else {
m.logger.Info("Marked pool as offline (not found in system)", "pool", poolName)
m.logger.Info("Removed missing pool from database", "pool", poolName)
}
}
}