After patching, services must be restarted in order: database, then API, then web, each healthy before the next. Script it.
BeginnerScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → Ordered restart with a health gate per step, stopping on the first failure.
What I'd do →
declare -A check=(
[postgresql]='pg_isready -q'
[api]='curl -fsS -o /dev/null --max-time 3 http://127.0.0.1:8080/readyz'
[nginx]='curl -fsS -o /dev/null --max-time 3 http://127.0.0.1/'
)
for svc in postgresql api nginx; do
systemctl restart "$svc"
for _ in {1..30}; do bash -c "${check[$svc]}" && continue 2; sleep 2; done
echo "$svc not healthy after restart, stopping" >&2; exit 1
done
echo "all services healthy"
continue 2jumps to the next service once its check passes.- The array keeps order explicit (associative arrays do not preserve it; the
forlist does).
Why → Restarting dependents before their dependency is healthy just creates a second wave of errors.
Interview tip → Mention systemd After=/Requires= for boot ordering, and that health gating still needs a check like this.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate