[ norboten ]
bash · lab bash-01

The Deploy That Took the Site Down

· about 30 minutes · runs on ubuntu-26.04-devops · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

The web server serves whatever /srv/www/current points at. Releases are unpacked next to it, in /srv/www/releases/, by deploy-site:

deploy-site /tmp/release-2026-09-13.tar.gz

Last night a release archive arrived truncated. deploy-site printed deployed, exited 0, and the site served an empty directory until someone noticed in the morning. The on-call engineer also says the script "does something strange" when it is run twice quickly, and that it failed outright on the staging box, where the web root is /srv/web root/ — with a space.

What is expected, and graded — the grader runs deploy-site itself, against its own directories, through the SITE_ROOT variable the script already reads:

  1. A good archive becomes the live release, even when SITE_ROOT contains spaces.
  2. A corrupt or missing archive changes nothing: current still points at the previous release, no half-unpacked release is left behind, and the script exits non-zero.
  3. Run with no argument, it prints a usage message to standard error, exits non-zero and changes nothing.
  4. Two deploys straight after each other produce two separate releases, and current ends on the second.

You have root through sudo. Everything must still hold after a reboot.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_good_release_goes_liveQuote paths so that a directory with spaces works
02_bad_release_changes_nothingStop a script at the first failure and report it with a non-zero exit status
03_no_argument_changes_nothingStop a script at the first failure and report it with a non-zero exit status
04_two_deploys_in_a_rowSwitch a release atomically, and keep every release in its own directory

Start it

  1. 2Labs
  2. bash-01select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

What does this print?

f() { false; echo "after"; }
f
echo "status=$?"
Question 2

A symlink `current` points to the directory `releases/a`. What does `ln -sf releases/b current` do?

Question 3

Why is `ln -sfn new .tmp && mv -Tf .tmp current` preferred to `rm current && ln -s new current` for a live switch?