Interview Prep/Shell Scripting/Scenarios: deployments, user management and fleet operations

After a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?

IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer

Situation read → A single failed probe during warm-up should not trigger rollback; sustained failure should.

What I'd do →

ok=0 fail=0
for _ in $(seq 1 30); do
  if curl -fsS -o /dev/null --max-time 3 http://127.0.0.1:8080/readyz; then
    ok=$((ok + 1)); fail=0
    (( ok >= 5 )) && { echo "healthy"; exit 0; }
  else
    fail=$((fail + 1)); ok=0
    (( fail >= 5 )) && break
  fi
  sleep 2
done
rollback "$previous"; exit 1
  1. Require 5 consecutive successes to pass and 5 consecutive failures to fail, within an overall deadline.

Why → Consecutive-count thresholds smooth out warm-up noise while still failing fast on real breakage.

Interview tip → Mention this mirrors Kubernetes successThreshold/failureThreshold and ALB healthy/unhealthy thresholds.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations