Files
haproxy-openmanager/backend/utils/agent_scripts
taylanbakircioglu b3b0544b11 fix: Agent stop timeout - graceful shutdown with signal handling
PROBLEM:
- Agent stop took ~90 seconds (systemd default timeout)
- No signal handling (trap) - SIGTERM ignored during sleep 30
- Uninterruptible sleep blocked graceful shutdown

SOLUTION:
1. Signal Handler
   - Added trap handler for SIGTERM/SIGINT/SIGQUIT
   - SHUTDOWN_REQUESTED flag for graceful exit

2. Interruptible Sleep
   - Changed: sleep 30 → 30x sleep 1
   - Check shutdown flag every second
   - Agent stops in 1-2 seconds instead of 90

3. Improved Stop Command
   - Graceful SIGTERM → wait 5s → force SIGKILL
   - Verification that process actually stopped
   - User feedback during stop operation

4. Systemd Timeout Configuration (Linux)
   - TimeoutStopSec=10 (instead of default 90s)
   - KillMode=mixed (SIGTERM main, SIGKILL others)
   - KillSignal=SIGTERM (explicit)

IMPACT:
- Stop time: 90s → 1-2s (98% improvement)
- Config apply:  SAFE - completes before shutdown
- HAProxy reload:  SAFE - subprocess not affected
- Stats sending:  SAFE - heartbeat completes
- Agent upgrade:  SAFE - upgrade completes
- Backward compatible:  YES

TECHNICAL DETAILS:
- Bash signal handling: functions complete atomically
- Subprocess isolation: systemctl/curl not interrupted
- Loop control timing: check only between functions

FILES CHANGED:
- backend/utils/agent_scripts/linux_install.sh (+79 lines)
- backend/utils/agent_scripts/macos_install.sh (+68 lines)
2025-11-12 14:10:16 +03:00
..