📚 Encyclopedia

Servers & Hosting · updated 2026-11-02

Deploy scripts with rsync (patterns and traps)

deployrsyncgit-archivebashversion-stamp

Most of Justin's sites deploy with a small deploy.sh that builds locally and rsyncs to the server docroot over SSH. The pattern is simple, but the details (what gets deleted, what gets shipped, permissions, labels) decide whether a deploy is safe. These are the variants that worked and the traps they guard against.

Building blocks

Ship committed state, not the working tree

git archive HEAD | tar -x -C "$STAGE" then rsync the stage. Uncommitted changes can never ship by accident, which matters when experiments live in the same tree. hampton.website's API and the standalone Forge API deploy this way. The web build can instead refuse to run if source files are dirty (git diff --quiet -- src angular.json package*.json || exit 1).

Version stamps

Write {"commit": "<sha>", "deployed": "<date>"} to version.json in each target during deploy. Then curl https://site/version.json answers "what is live" in one request. Webpack style content-hash filenames are also build fingerprints: identical hash means identical content.

Staging-directory permission trap

mktemp -d creates the directory with mode 700. rsync with -a copies that mode onto the served directory, Apache (a different user) can no longer traverse it, and every URL returns 403. Fix: chmod 755 "$STAGE" right after mktemp. If a deploy suddenly 403s everything, check ls -ld on the docroot.

Batching many server changes

When one change touches many files on the server (several vhosts, configs, scripts), send them in one transfer, not one scp per file: - Stage everything in a single local directory that mirrors the destination layout, then send it with one rsync -a stage/ server:/tmp/stage/ and install from there in one SSH session (sudo cp, restorecon, reload). On 2026-10-30, while moving six sites to new hostnames, a run of back-to-back scp calls stalled the SSH connection for about 15 minutes; one rsync of the same files went straight through. Each scp is a fresh SSH handshake, and a burst of them can trip connection rate limits or simply hang on a 1-vCPU server. - Back up what you are about to replace first (cp -a /etc/httpd/conf.d /etc/nginx/conf.d into a dated directory such as /root/vhost-backup-YYYYMMDD/), so a bad batch is one copy away from undone. - Gate every reload on both config tests: apachectl configtest && nginx -t && systemctl reload httpd nginx. Read the warnings nginx -t prints even when it succeeds: "conflicting server name ... ignored" means two files claim the same host and the first one loaded keeps winning (see nginx in front of Apache (TLS proxy on :8008)).

Pre-deploy checks

Lessons from Run's deploy.sh (Flutter web + APK + PHP API)

Building legacy front ends

Old webpack 4 toolchains (Angular 11 here) fail on Node 17 and later with OpenSSL errors. Build with NODE_OPTIONS=--openssl-legacy-provider npx ng build --prod; Angular 11 built fine on Node 22 that way. Sweep stale hashed bundles from the target explicitly when deploying without --delete.

Retiring an old Flutter web app

When replacing a Flutter web app with anything else, ship a self-destructing flutter_service_worker.js at the same URL that unregisters itself and clears caches. Otherwise returning visitors keep getting the old app from the service worker cache.

See also

Linked from

Sources: hunsley memory (hhs-deployment), hampton-website memory (deploy), plumb memory (deployment), jah memory (justinahampton-site), global CLAUDE.md, run memory (feedback-api-local-only.md, session-v085.md, mobile-shell.md, architecture-audit-2026-10.md), hub memory (hub-index), 2026-10-30