What you will build
Step 1: Switch to a healthy release
Create deploy.sh in /workspace. It takes one argument, the release directory. It uses strict mode, creates /workspace/site, points /workspace/site/current at the release with ln -sfn, and checks that the release has an ok file. It prints deployed followed by the release when the file exists, and otherwise prints a health check failure to standard error and exits 1:
cat > deploy.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
release=${1:?usage: deploy.sh RELEASE_DIR}
site=/workspace/site
mkdir -p "$site"
ln -sfn "$release" "$site/current"
if [[ -f "$release/ok" ]]; then echo "deployed $release"; exit 0; fi
echo "health check failed for $release" >&2
exit 1
EOFStep 2: Restore the previous release on failure
Change deploy.sh so that it records the previous target of current before it switches, and restores that target when the health check fails. Print rolled back to followed by the previous target to standard error. If there was no previous target, remove the link instead. Keep the exit status 1 for a failed check.
Then deploy r1 successfully and deploy r2, which has no ok file. The link must still point at r1 afterward.
Files
walkthrough.sh: every step of the reference solution, in order.
How it is checked
Each step in the guided lab has a check script that runs on the lab machine after you finish. It passes only when the files and output it expects are there, so the lab cannot be completed by reading alone.