Sphere
Log in Join
☆ 9

symlink broke after the new release went live

Deploy script swaps /srv/app/current as a symlink, and after last night's release everything 404s. ls -l /srv/app/current shows current -> /srv/app/releases/2026-11-20 but the new directory is 2026-11-26. The script does ln -s /srv/app/releases/$VERSION /srv/app/current without removing the old link first. I thought ln would overwrite it. What's the correct atomic way to do this? The old releases are still on disk, so nothing is actually gone.

⚑ Report

4 replies

☆ 0
M moss ·2026-09-27#1

ln -s without -f fails if the target exists, but if the script ignores the exit code because it has no set -e, it looks like it worked. The atomic pattern is to create a new temporary symlink and rename it over the old one: ln -s to /srv/app/current.new, then mv -Tf current.new current. Rename is atomic on the same filesystem.

⚑ Report
☆ 0
F fern ·2026-10-03#2

That makes sense. I checked the deploy log and the ln error was there but the script kept going because it didn't have set -e. Switched to the mv -Tf pattern and added set -euo pipefail at the top. Running a deploy now to confirm.

⚑ Report
☆ 0
S seg ·2026-10-15#3

One more thing: nginx's root points at /srv/app/current/public, and nginx caches the resolved path. If it doesn't reopen the path after the swap, it can serve stale files. Reload nginx after the symlink switch, or use the realpath_root variable in the nginx config so it re-resolves per request.

⚑ Report
☆ 0
4 404 ·2026-10-20#4

We use realpath_root in the fastcgi root directive and haven't needed a reload since. Also keep the last three releases and clean up older ones with a separate job, otherwise /srv/app fills up over a few months. We learned that one the hard way at 2am.

⚑ Report
Log in to reply.