Skip to main content

Web frameworks · Intermediate · 35 min

Deploy the library app to a Linux server with Node, systemd and Nginx

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Node.js 26.13 · Next.js 16.4 · Nginx 1.30 · ubuntu:26.04 image

You will build the community library app as a standalone Next.js release, run it on an Ubuntu 26.04 server as a systemd service behind Nginx with its SQLite database in /var/lib, apply migrations on every deploy and back the database up every night.

On this page

The library app is finished: a searchable catalogue, librarians who sign in, lending that stays correct under double clicks, caching and tests. In this last part it leaves your laptop. You build it once as a self-contained release, copy that release to an Ubuntu 26.04 server, and run it there the way a small production service should run: as its own unprivileged user, started and restarted by systemd, behind Nginx, with the database in /var/lib and a backup every night.

The plan, from the outside in:

  • Nginx answers on port 80 (and 443 once you add HTTPS), serves the built JavaScript and CSS files straight from disk and passes every other request to the app.
  • The app is Next.js's standalone server.js, listening on 127.0.0.1:3000 only, so nothing outside the server reaches it except through Nginx.
  • systemd starts the app at boot, restarts it if it crashes, and runs a nightly backup.
  • SQLite keeps the whole library in one file, /var/lib/community-library/library.db, owned by the library user.

Why not a serverless host such as Vercel? This app writes to a file on local disk. Serverless functions have no persistent local file system: each copy of the function gets a fresh, mostly read-only one that disappears when it finishes, and several copies can run at once without sharing anything. Every loan you recorded would vanish. To run this app on Vercel you would move the data to a hosted database (Drizzle also supports libSQL and PostgreSQL drivers), keep the migrations, and change src/db/connect.ts to use the new driver. How to Deploy a Next.js 16 App to Vercel covers the platform side. One small server with a file on its disk is the simpler choice for one library, and it costs little to run.

Every command block below starts with a comment saying where it runs: # On your laptop or # On the server.

Step 1 · Build a standalone release on your laptop

A normal npm run start needs the whole project and all of node_modules next to it. Next.js can instead trace which files the server really loads and copy only those into .next/standalone, together with a small server.js that starts the app. That folder is the release: you copy it to the server and run it with node, with no npm install there. On a server with 1 GB of memory this also spares you a build that might run out of memory.

Two things in this app need help from the tracer:

  • better-sqlite3 chooses its compiled SQLite binary when it starts, from a prebuilds folder with one file per system (linux-x64.node, linux-arm64.node, darwin-arm64.node and so on). The tracer cannot see that choice, and your laptop may not even be the same kind of machine as the server. Including the whole folder ships every binary, about 16 MB, and the server picks its own.
  • The migration runner you add below uses drizzle-orm/better-sqlite3/migrator, which no page imports, so the tracer would leave it out.

Open next.config.ts and add the output and outputFileTracingIncludes keys. Keep cacheComponents and anything else you set in earlier parts. With only those, the file reads:

TypeScript
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  cacheComponents: true,
  output: "standalone",
  outputFileTracingIncludes: {
    "/*": [
      "./node_modules/better-sqlite3/prebuilds/**/*",
      "./node_modules/drizzle-orm/**/*",
    ],
  },
};

export default nextConfig;

The key "/*" is a pattern for routes: the extra files are added to the traces of the app's routes, and the standalone folder copies them.

The server will apply migrations itself, but drizzle-kit is a development tool and is not in the release. Drizzle ORM has its own migrate() function that reads the same drizzle folder and records what it applied in the same __drizzle_migrations table, so the server and your laptop always agree. Write a small script for it:

Bash
# On your laptop
cd ~/community-library-demo
cat > scripts/migrate.mjs <<'JS'
// Applies the migrations in ./drizzle that the database has not had yet.
// Runs from the release folder on the server: node migrate.mjs
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";

const file = process.env.DATABASE_FILE;
if (!file) {
  console.error("Set DATABASE_FILE to the database to migrate.");
  process.exit(1);
}

const sqlite = new Database(file);
sqlite.pragma("journal_mode = WAL");
const applied = () =>
  sqlite.prepare("select count(*) as n from sqlite_master where name = '__drizzle_migrations'").get().n
    ? sqlite.prepare("select count(*) as n from __drizzle_migrations").get().n
    : 0;

const before = applied();
const folder = join(dirname(fileURLToPath(import.meta.url)), "drizzle");
migrate(drizzle({ client: sqlite }), { migrationsFolder: folder });
const after = applied();
console.log(`Migrations: ${after - before} applied, ${after} in total.`);
sqlite.close();
JS

Now build, and put the release together in a release folder. The standalone server does not include the public folder or the built browser files in .next/static, so you copy those in, then the migrations and the script. The last lines pack it into one file and keep both out of Git:

Bash
# On your laptop
npm run build
rm -rf release release.tar.gz
mkdir release
cp -R .next/standalone/. release/
cp -R .next/static release/.next/static
cp -R public release/public
cp -R drizzle release/drizzle
cp scripts/migrate.mjs release/migrate.mjs
rm -rf release/data release/.env release/.env.production
tar -czf release.tar.gz -C release .
printf '\n# Deploy builds\n/release/\n/release.tar.gz\n' >> .gitignore

The rm -rf release/data ... line makes sure no database file and no .env file travel with the code. Next.js copies .env and .env.production into the standalone folder if the build loaded them; the server gets its settings from its own file instead. .env.local, where part 5 keeps the sign-in secret, is never copied.

Check it worked

Bash
# On your laptop
ls release
ls release/node_modules/better-sqlite3/prebuilds
test -f release/node_modules/drizzle-orm/better-sqlite3/migrator.js && echo "migrator included"
ls -lh release.tar.gz

ls release shows server.js, migrate.mjs, package.json, drizzle, node_modules and public (and the hidden .next). The prebuilds listing includes linux-x64.node and linux-arm64.node, and the next line prints migrator included. The archive is something like 40 to 60 MB. That is the only thing you upload, which matters on metered or prepaid data: the server downloads nothing from npm.

Try the release on its own before it leaves your laptop. Point the migration script at a new, empty database inside the ignored data folder:

Bash
# On your laptop
DATABASE_FILE=data/migrate-test.db node release/migrate.mjs
ls drizzle/*.sql | wc -l
rm -f data/migrate-test.db data/migrate-test.db-wal data/migrate-test.db-shm

The script prints Migrations: N applied, N in total., where N is the number of SQL files the second command counts. The release can create the whole schema with nothing but Node.js.

Step 2 · Prepare the server

The rest happens on the server, except for one upload. Install the SQLite command-line tool for checks and backups, and openssl for generating a secret, then confirm Node.js:

Bash
# On the server
sudo apt update
sudo apt install -y sqlite3 openssl curl
node --version

Create a system user for the app. It has no password and no login shell, so a flaw in the app cannot become a login on the server:

Bash
# On the server
sudo useradd --system --user-group --no-create-home --home-dir /var/lib/community-library --shell /usr/sbin/nologin library

Then the folders. Each has one job, and the library user can write only to its data and its backups:

Bash
# On the server
sudo install -d -m 755 /opt/community-library /opt/community-library/releases
sudo install -d -o library -g library -m 750 /var/lib/community-library /var/backups/community-library
sudo install -d -o root -g library -m 750 /etc/community-library
  • /opt/community-library/releases holds one folder per deploy, owned by root, so the running app cannot change its own code. A link called current points at the live one.
  • /var/lib/community-library holds the database. /var/lib is where Linux keeps a service's state, and it is the folder you back up.
  • /var/backups/community-library holds the nightly copies.
  • /etc/community-library holds the settings file with the secret. Root owns it and only the library group can read it.

Check it worked

Bash
# On the server
node --version
id library
ls -ld /opt/community-library/releases /var/lib/community-library /var/backups/community-library /etc/community-library

node --version prints v26. and a patch number. id library shows a user and group called library. The ls lines show /var/lib/community-library and /var/backups/community-library owned by library with drwxr-x---, and /etc/community-library owned by root with group library.

Step 3 · Upload the release and the starting database

The server needs a database to start from. The simplest is a copy of your laptop's: it already has the books, the members and the librarian account from part 5, and every migration applied. Do not copy data/library.db with cp while anything has it open. SQLite in WAL mode keeps recent changes in library.db-wal until they are folded into the main file, and a plain copy can miss them. better-sqlite3's backup() makes a complete, consistent copy:

Bash
# On your laptop
cd ~/community-library-demo
node -e 'require("better-sqlite3")("data/library.db").backup("data/library-start.db").then(() => console.log("Wrote data/library-start.db"))'

Upload both files to the server's /tmp. Replace you@your-server with your SSH user and the server's address or name:

Bash
# On your laptop
scp release.tar.gz you@your-server:/tmp/library-release.tar.gz
scp data/library-start.db you@your-server:/tmp/library-start.db

On the server, unpack the release into a folder named after the date and time, and point current at it. --no-same-owner makes root the owner of every file, whatever user built it on the laptop. If you built on a Mac, GNU tar may print warnings about unknown extended header keywords; they are macOS file attributes and are safe to ignore.

Bash
# On the server
RELEASE=/opt/community-library/releases/$(date +%Y%m%d-%H%M%S)
sudo mkdir -p "$RELEASE"
sudo tar -xzf /tmp/library-release.tar.gz -C "$RELEASE" --no-same-owner
sudo install -d -o library -g library "$RELEASE/.next/cache"
sudo ln -sfn "$RELEASE" /opt/community-library/current
rm /tmp/library-release.tar.gz

The install -d line gives the app one writable folder inside its release. Next.js keeps its server cache on local disk, under .next, and the rest of the release stays read-only to the app.

Now put the database in place, owned by library. This command refuses to replace a database that is already there, so running it again by mistake on a live server cannot wipe the library's records:

Bash
# On the server
if sudo test -e /var/lib/community-library/library.db; then echo "library.db already exists; not replacing it"; else sudo install -o library -g library -m 640 /tmp/library-start.db /var/lib/community-library/library.db; fi
rm /tmp/library-start.db

Check it worked

Bash
# On the server
ls -l /opt/community-library/
ls /opt/community-library/current
sudo ls -l /var/lib/community-library

The first listing shows current -> /opt/community-library/releases/ followed by the date and time, and the second shows server.js and migrate.mjs. The last shows library.db owned by library library with -rw-r-----.

Step 4 · Keep the settings in a private environment file

The app reads its settings from environment variables. systemd loads them from a file, so they never sit in the unit file, the code or Git. Create the file empty with its final permissions first, so the secret is never in a readable file, even for a moment:

Bash
# On the server
sudo install -m 640 -o root -g library /dev/null /etc/community-library/library.env

Add the plain settings. Replace library.example.org with your own domain, or http:// and the server's IP address until you have one:

Bash
# On the server
sudo tee -a /etc/community-library/library.env > /dev/null <<'ENV'
HOSTNAME=127.0.0.1
PORT=3000
DATABASE_FILE=/var/lib/community-library/library.db
BETTER_AUTH_URL=https://library.example.org
ENV
  • HOSTNAME and PORT tell the standalone server.js where to listen. Without HOSTNAME=127.0.0.1 it listens on every network address, and port 3000 would be open to the internet beside Nginx.
  • DATABASE_FILE is the variable src/db/connect.ts has read since part 2.
  • BETTER_AUTH_URL is the address people use to reach the app. Better Auth builds its links and checks request origins against it.

Better Auth also needs a long random secret to sign sessions. Generate it on the server and append it through a pipe, so it never appears on a command line or in your shell history:

Bash
# On the server
{ printf 'BETTER_AUTH_SECRET='; openssl rand -base64 32; } | sudo tee -a /etc/community-library/library.env > /dev/null

The server's secret differs from the one in your laptop's .env.local, so sessions from your laptop do not carry over: librarians sign in again on the server. Their passwords still work, because they are stored in the database you copied. If you use part 7's /api/revalidate endpoint on the server, append a REVALIDATE_TOKEN line the same way, with openssl rand -hex 32 in place of the base64 secret; without that line the endpoint refuses every request.

Check it worked

Bash
# On the server
sudo ls -l /etc/community-library/library.env
sudo grep -c '^BETTER_AUTH_SECRET=' /etc/community-library/library.env
sudo grep -v '^BETTER_AUTH_SECRET=' /etc/community-library/library.env

The ls line starts with -rw-r----- and shows root library. The first grep prints 1, which proves the secret is there without showing it. The second prints the four plain settings.

Step 5 · Run the migrations as the library user

Every deploy runs the migration script before the new code starts. A small wrapper loads the settings file and runs it from the live release. Write it once:

Bash
# On the server
sudo install -m 755 /dev/null /opt/community-library/migrate
sudo tee /opt/community-library/migrate > /dev/null <<'SH'
#!/bin/sh
# Applies new database migrations from the live release, with the app's settings.
set -eu
cd /opt/community-library/current
set -a
. /etc/community-library/library.env
set +a
exec node migrate.mjs
SH

Run it as library, never as root. Here is why. The first time SQLite opens a WAL database, it creates library.db-wal and library.db-shm next to it, owned by whoever opened it. If root creates them, the app, running as library, cannot write to them and fails with attempt to write a readonly database. The same goes for any sqlite3 command you run against the live file: use sudo -u library.

Bash
# On the server
sudo -u library /opt/community-library/migrate

Check it worked

The script prints Migrations: 0 applied, N in total. Your laptop had already applied every migration to the copy you uploaded, so there was nothing to do. On a later deploy with a new migration it says 1 applied. Look inside the database as library:

Bash
# On the server
sudo -u library sqlite3 /var/lib/community-library/library.db 'select count(*) from __drizzle_migrations; select count(*) from books;'
sudo ls -l /var/lib/community-library

The first command prints the number of migrations, then the number of books (20 if you kept the demo catalogue). The listing now shows library.db-wal and library.db-shm too, all owned by library.

Step 6 · Run the app as a systemd service

The unit file says who runs the app, where, with which settings, and what to do if it stops. Run an app as a systemd service explains units in depth; this one is ready to use:

Bash
# On the server
sudo tee /etc/systemd/system/community-library.service > /dev/null <<'UNIT'
[Unit]
Description=Community library (Next.js)
After=network.target

[Service]
Type=simple
User=library
Group=library
WorkingDirectory=/opt/community-library/current
EnvironmentFile=/etc/community-library/library.env
ExecStart=/usr/bin/node server.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true
ProtectHome=true
ProtectSystem=full

[Install]
WantedBy=multi-user.target
UNIT

What the less obvious lines do:

  • WorkingDirectory follows the current link when the service starts, so a restart after you move the link runs the new release.
  • Restart=on-failure with RestartSec=5 brings the app back five seconds after a crash.
  • NoNewPrivileges, PrivateTmp, ProtectHome and ProtectSystem=full take away things the app never needs: gaining privileges, sharing /tmp with other programs, reading home folders, and writing to /usr, /boot or /etc.

Load the unit, start it, and make it start at boot:

Bash
# On the server
sudo systemctl daemon-reload
sudo systemctl enable --now community-library.service
sudo systemctl status community-library.service --no-pager

The status shows active (running) and, in the last log lines, Next.js reporting Ready.

Check it worked

Ask the app directly, on the server:

Bash
# On the server
curl -s http://127.0.0.1:3000/books/3 | grep -o '<h1>[^<]*</h1>'
curl -s -o /dev/null -w 'catalogue: %{http_code}\n' http://127.0.0.1:3000/books

The first prints <h1>Weep Not, Child</h1>: the book you have known as /books/3 since part 1, read from /var/lib/community-library/library.db. The second prints catalogue: 200. If either fails, read the app's log with journalctl -u community-library.service -n 50 --no-pager. A message mentioning readonly database means a file in /var/lib/community-library is owned by root; fix it with sudo chown -R library:library /var/lib/community-library.

Step 7 · Put Nginx in front

The app is up but only reachable from the server itself. Nginx takes requests from the internet and passes them to it. How to Put Nginx in Front of a Node.js App explains each proxy header. This site file adds two things for Next.js. It serves /_next/static/ straight from the release, because those files have a content hash in their names and never change, so browsers may keep them for a year. And it turns off response buffering for the app, so pages that stream (the catalogue shows its loading placeholder first, from part 3) reach the browser as they render instead of all at the end.

Replace library.example.org with your domain:

Bash
# On the server
sudo tee /etc/nginx/conf.d/community-library.conf > /dev/null <<'NGINX'
server {
    listen 80;
    server_name library.example.org;

    location /_next/static/ {
        alias /opt/community-library/current/.next/static/;
        add_header Cache-Control "public, max-age=31536000, immutable";
        access_log off;
    }

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}
NGINX
sudo nginx -t

Host $host matters for this app. Server actions check that a form was posted from the same site, by comparing the browser's Origin header with the host the request arrived for, so the app must see your real domain, not 127.0.0.1. nginx -t must print syntax is ok and test is successful. Then apply it:

Bash
# On the server
sudo systemctl reload nginx

Check it worked

The Host header stands in for your domain until its DNS points at the server:

Bash
# On the server
curl -s -H 'Host: library.example.org' http://127.0.0.1/books/3 | grep -o '<h1>[^<]*</h1>'
FILE=$(cd /opt/community-library/current/.next/static && find . -name '*.css' -print -quit | cut -c3-)
curl -sI -H 'Host: library.example.org' "http://127.0.0.1/_next/static/$FILE" | grep -i '^cache-control\|^server'

The first prints <h1>Weep Not, Child</h1>, this time through Nginx. The second shows Server: nginx and Cache-Control: public, max-age=31536000, immutable for one of the built CSS files, served from disk without touching Node.js. Open http://library.example.org/books (or the server's IP address) in a browser, sign in as a librarian, and lend and return a book: the change is written to the file in /var/lib.

A public site needs HTTPS before librarians type passwords into it. Follow Free HTTPS with Let's Encrypt and Nginx for this server name. Certbot adds the certificate to this same file. Make sure BETTER_AUTH_URL starts with https://, then restart the app with sudo systemctl restart community-library.service so it reads the file again.

Step 8 · Back up the database every night

The whole library is one file, which makes backups simple, but copying it with cp while the app writes can produce a broken copy, for the WAL reason from step 3. The sqlite3 tool's .backup command copies a live database safely. This script makes a copy, checks it, compresses it and deletes copies older than two weeks:

Bash
# On the server
sudo install -m 755 /dev/null /usr/local/sbin/library-backup
sudo tee /usr/local/sbin/library-backup > /dev/null <<'SH'
#!/bin/sh
# Copies the library database to /var/backups/community-library and keeps 14 days of copies.
set -eu
DB=/var/lib/community-library/library.db
DIR=/var/backups/community-library
COPY="$DIR/library-$(date +%Y%m%d-%H%M%S).db"
sqlite3 "$DB" ".backup '$COPY'"
if [ "$(sqlite3 "$COPY" 'pragma integrity_check;')" != "ok" ]; then
  echo "Integrity check failed for $COPY" >&2
  exit 1
fi
gzip "$COPY"
find "$DIR" -name 'library-*.db.gz' -mtime +14 -delete
echo "Backed up to $COPY.gz"
SH

A oneshot service runs the script as library, and a timer starts it every night. Persistent=true runs a missed backup at the next boot if the server was off at 02:30, and RandomizedDelaySec spreads the start over a quarter of an hour. UMask=0077 makes each copy readable by library only:

Bash
# On the server
sudo tee /etc/systemd/system/library-backup.service > /dev/null <<'UNIT'
[Unit]
Description=Back up the community library database

[Service]
Type=oneshot
User=library
Group=library
UMask=0077
ExecStart=/usr/local/sbin/library-backup
UNIT
sudo tee /etc/systemd/system/library-backup.timer > /dev/null <<'UNIT'
[Unit]
Description=Nightly backup of the community library database

[Timer]
OnCalendar=*-*-* 02:30:00
RandomizedDelaySec=15m
Persistent=true

[Install]
WantedBy=timers.target
UNIT

Enable the timer, then run one backup now rather than waiting for the night:

Bash
# On the server
sudo systemctl daemon-reload
sudo systemctl enable --now library-backup.timer
sudo systemctl start library-backup.service
systemctl list-timers library-backup.timer --no-pager

Check it worked

list-timers shows library-backup.timer with tonight's date and a time between 02:30 and 02:45 in its NEXT column. A backup you have never restored is a hope, not a backup, so restore the newest copy to a scratch file and count the books in it:

Bash
# On the server
sudo ls -l /var/backups/community-library
LATEST=$(sudo sh -c 'ls -t /var/backups/community-library/library-*.db.gz | head -n 1')
sudo gunzip -c "$LATEST" > /tmp/restore-test.db
sqlite3 /tmp/restore-test.db 'select count(*) from books;'
rm /tmp/restore-test.db

The listing shows one library-<date>-<time>.db.gz file owned by library. The count matches the live database: 20 if you kept the demo catalogue.

A copy on the same disk does not survive the disk, or the server being deleted. Copy the newest file off the server regularly, to your laptop or to object storage. Compressed, this database is a few hundred kilobytes, so even a daily download costs almost nothing on prepaid data.

Step 9 · Ship an update, roll back, and clean up

Every later deploy repeats the same moves. On your laptop, rebuild the release and upload it, as in steps 1 and 3:

Bash
# On your laptop
cd ~/community-library-demo
npm run build
rm -rf release release.tar.gz
mkdir release
cp -R .next/standalone/. release/
cp -R .next/static release/.next/static
cp -R public release/public
cp -R drizzle release/drizzle
cp scripts/migrate.mjs release/migrate.mjs
rm -rf release/data release/.env release/.env.production
tar -czf release.tar.gz -C release .
Bash
# On your laptop
scp release.tar.gz you@your-server:/tmp/library-release.tar.gz

On the server, back up first, then unpack the new release, switch current to it, migrate, and restart:

Bash
# On the server
sudo systemctl start library-backup.service
Bash
# On the server
RELEASE=/opt/community-library/releases/$(date +%Y%m%d-%H%M%S)
sudo mkdir -p "$RELEASE"
sudo tar -xzf /tmp/library-release.tar.gz -C "$RELEASE" --no-same-owner
sudo install -d -o library -g library "$RELEASE/.next/cache"
sudo ln -sfn "$RELEASE" /opt/community-library/current
rm /tmp/library-release.tar.gz
Bash
# On the server
sudo -u library /opt/community-library/migrate
sudo systemctl restart community-library.service

The restart takes a second or two, during which Nginx answers 502. For one library that is fine; do it outside opening hours if you like.

To roll back, point current at the previous release and restart. List the releases, newest last, and replace <previous-release> with the folder name you want:

Bash
# On the server
ls /opt/community-library/releases
sudo ln -sfn /opt/community-library/releases/<previous-release> /opt/community-library/current
sudo systemctl restart community-library.service

Rolling back the code does not undo a migration. Drizzle migrations only go forward, so if the new release changed a table in a way the old code cannot read, restore the backup you made before the deploy as well. Three details matter here. Decompress as library, not through a root shell redirect, so the restored file stays owned by library and the app can write to it. Delete the old library.db-wal and library.db-shm with the service stopped, because SQLite would otherwise replay the stale WAL on top of the restored copy. And stop the service first, so nothing writes while the file is swapped. Replace <backup> with the file name from sudo ls -t /var/backups/community-library (the newest one before the deploy):

Bash
# On the server
sudo systemctl stop community-library.service
sudo -u library sh -c 'gunzip -c /var/backups/community-library/<backup>.db.gz > /var/lib/community-library/library.db'
sudo rm -f /var/lib/community-library/library.db-wal /var/lib/community-library/library.db-shm
sudo systemctl start community-library.service

Confirm the restored file belongs to library and holds the books you expect:

Bash
# On the server
sudo ls -l /var/lib/community-library/library.db
sudo -u library sqlite3 /var/lib/community-library/library.db 'select count(*) from books;'

The file is owned by library library, and the count matches the backup: 20 if you kept the demo catalogue. If the app log shows attempt to write a readonly database, fix the ownership with sudo chown -R library:library /var/lib/community-library and restart the service.

Keep the last three releases or so and delete older ones with sudo rm -rf /opt/community-library/releases/<old-release>, never the one current points at.

Check it worked

Bash
# On the server
ls /opt/community-library/releases
readlink /opt/community-library/current
curl -s -H 'Host: library.example.org' http://127.0.0.1/books/3 | grep -o '<h1>[^<]*</h1>'

There are now two release folders, current points at the newer one, and the site still prints <h1>Weep Not, Child</h1> with every book and loan intact.

Clean up the local demo

This is the last part of the series, so you can now remove the working copy on your laptop. The next command deletes ~/community-library-demo with all nine parts of code, its local database and the release files, and cannot be undone. If you want to keep the code, push it to a Git host or copy the folder somewhere first. The server keeps running from its own copy either way.

Bash
# On your laptop
rm -rf ~/community-library-demo

Remove it from a practice server

Skip this if the server is your library's real one. On a server you only used to practise, this deletes the app, its database, every backup and its secret, and cannot be undone. Stop the units first:

Bash
# On the server
sudo systemctl disable --now library-backup.timer community-library.service
Bash
# On the server
sudo rm /etc/systemd/system/community-library.service /etc/systemd/system/library-backup.service /etc/systemd/system/library-backup.timer
sudo rm /etc/nginx/conf.d/community-library.conf
sudo nginx -t
sudo rm -rf /opt/community-library /var/lib/community-library /var/backups/community-library /etc/community-library /usr/local/sbin/library-backup
sudo userdel library
Bash
# On the server
sudo systemctl daemon-reload
sudo systemctl reload nginx

id library now reports no such user, ls ~/community-library-demo on your laptop reports No such file or directory, and nginx -t printed test is successful without the site file.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.