A developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?
IntermediateScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → A watchdog loop is a fragile supervisor: it can die itself, misses fast crash loops, and has no backoff or logging.
What I'd do →
- Run the app as a systemd service with restart policy:
[Service] ExecStart=/srv/app/current/bin/server Restart=on-failure RestartSec=5 StartLimitIntervalSec=300 StartLimitBurst=5 - Add
WatchdogSec=if the app can sendsd_notifyheartbeats, which catches hangs, not just exits. - Alert via
OnFailure=when the start limit is hit. - In Kubernetes, the equivalent is liveness probes and the restart policy.
Why → The init system already supervises processes reliably, with logging and rate limiting.
Interview tip → Say "don't write a supervisor in Bash" and name the systemd directives.
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?AdvancedHow do you know a scheduled job actually ran, not just that it did not report failure?Intermediate