Write the core of a deploy script with release directories, an atomic symlink switch and rollback.
IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → The "Capistrano layout" gives zero-downtime switching and instant rollback.
What I'd do →
base=/srv/app; release=$(date -u +%Y%m%dT%H%M%SZ); dir="$base/releases/$release"
mkdir -p "$dir"
tar -xzf "/tmp/app-$version.tgz" -C "$dir"
ln -sfn "$base/shared/.env" "$dir/.env"
previous=$(readlink -f "$base/current" || true)
ln -sfn "$dir" "$base/current.tmp" && mv -T "$base/current.tmp" "$base/current" # atomic switch
sudo systemctl reload app
if ! wait_for_http http://127.0.0.1:8080/readyz 60; then
echo "health check failed, rolling back to $previous" >&2
ln -sfn "$previous" "$base/current.tmp" && mv -T "$base/current.tmp" "$base/current"
sudo systemctl reload app
exit 1
fi
ln -sfnalone unlinks then creates;mv -Tof a temp link is a true atomicrename().- Keep the last N releases for rollback (see the cleanup in Q26).
Why → All preparation happens off to the side; the only live change is one rename.
Interview tip → Explain why mv -T matters: without it, mv would move the link into the existing current directory.
More on Scenarios: deployments, user management and fleet operations
Deploy 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.IntermediateYou are asked to audit a server for risky accounts. What does your script check?Intermediate