Files
haproxy-openmanager/backend/utils/agent_scripts
Taylan Bakırcıoğlu 132b59bcd7 feat(agent): preserve failed HAProxy configs for debugging (TESTED)
PROBLEM:
- When HAProxy validation fails, /tmp/haproxy-new-config.cfg is deleted
- Admins cannot inspect the failed config to diagnose syntax errors
- Debugging validation failures requires database queries

SOLUTION:
- Save failed configs with timestamp: /tmp/haproxy-failed-{version}-{timestamp}.cfg
- Automatic cleanup: keeps last 5 failed configs, deletes older ones
- Clear log messages with debug commands

IMPLEMENTATION:
- Minimal change in validation failed branch only
- Uses mv instead of rm for failed configs
- Successful configs still cleaned up (already copied to haproxy.cfg)
- TESTED: bash -n syntax validation passed for both scripts

BENEFITS:
- Easy inspection: cat /tmp/haproxy-failed-*.cfg
- Manual validation: haproxy -c -f /tmp/haproxy-failed-*.cfg
- Identifies config generation bugs quickly
- No disk space issues (auto-cleanup)

DEPLOYMENT:
- Zero risk: only affects validation failure path
- Use Script Management UI -> Reset to Default
- Then upgrade agents via Script Management

EXAMPLE LOG:
[INFO] DAEMON: Failed config saved to: /tmp/haproxy-failed-apply-consolidated-1763478044-20251118-150057.cfg
[INFO] DAEMON: Debug: cat /tmp/haproxy-failed-apply-consolidated-1763478044-20251118-150057.cfg
[INFO] DAEMON: Debug: haproxy -c -f /tmp/haproxy-failed-apply-consolidated-1763478044-20251118-150057.cfg
2025-11-18 21:58:05 +03:00
..