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

During a deploy you show a maintenance page. If the deploy fails, the page stayed up last time. Fix the script.

BeginnerScenarioScenarios: deployments, user management and fleet operations
Answer

Situation read → The removal step was at the end of the happy path, so any failure skipped it.

What I'd do →

maintenance_on()  { touch /srv/app/shared/maintenance.flag; }
maintenance_off() { rm -f /srv/app/shared/maintenance.flag; }

maintenance_on
trap maintenance_off EXIT
run_migrations
switch_release
  1. nginx serves the page when the flag exists: if (-f /srv/app/shared/maintenance.flag) { return 503; } with an error_page 503.
  2. The EXIT trap removes it on success, failure, or Ctrl+C.

Why → Traps make cleanup independent of which line failed.

Interview tip → Mention that a 503 with a Retry-After header is better for clients and SEO than a 200 maintenance page.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations