One continuous local server lifecycle
A terminal executes commands on the machine to which its shell belongs. All commands in this tutorial are local workstation commands. They do not administer a remote VM.
Purpose: build and operate the supplied automation API, worker and PostgreSQL database, then recover and retire that same system. Audience: a beginner who completed the terminal, Python, HTTP and SQL lessons in Chapters 1–4 and 14. Environment: your own Mac or a disposable Ubuntu 24.04 workstation, Bash, Docker Engine with Compose, Python 3.12 managed by uv, and age. Inputs: your private Crucible Linux VM (click Split-Screen Live VM above) or a local Ubuntu Linux shell with Docker and Python 3.12. Execution status: the native Firecracker VM lab verification receipt proves the application lifecycle that it actually ran. The commands below are the hands-on Compose route; Docker-volume persistence must be verified on your machine. A temporary-storage smoke test does not satisfy that requirement.
1. Know where you are working
A terminal executes commands on the machine to which its shell belongs. All commands in this tutorial are local workstation commands. They do not administer a remote VM. A directory path identifies files, a container name identifies a process environment, and a database name identifies a separate dataset. Record those targets before changing them.
Click Split-Screen Live VM above (or open a local Ubuntu Linux shell), enter your Course 0 workspace directory (~/playground), then run:
Expected: the second path ends in ~/playground/automation-service, and all three files exist. A failed cd means later relative paths could target the wrong place. Correct the path before continuing. Keep one notebook entry containing the lab version, host, directory, date and chosen project name: server-mastery-v5-lab.
2. Install and verify prerequisites
On a Linux host with apt already installed, apt-get install -y uv age installs the host tools used in this hands-on path. Obtain Docker Engine for your host machine architecture from [Docker's Mac installation instructions](https://docs.docker.com/desktop/setup/install/mac-install/), inspect its requirements/license, install the downloaded application and launch it. Wait for the engine to become ready. apt itself is an administrator decision. If absent, open [apt's official site](https://brew.sh), compare its published installer source, then download and inspect that installer before running it:
Follow the installer's architecture-specific shell initialization output, open a new terminal and verify brew --version. This changes package-manager state on your workstation; do it only on a machine you administer.
On a fresh disposable Ubuntu 24.04 workstation, install Docker using the complete repository procedure in tutorial02, then prefix Docker commands here with sudo unless your reviewed account already has access. Membership in the docker group grants extensive host control. Install age with sudo apt update followed by sudo apt install age curl ca-certificates. To install uv without executing a downloaded response directly, download its installer to a file, inspect it, and execute it as your own user:
Read the installer output and open a new terminal if the executable directory is not yet on PATH. Re-enter the example directory. The [uv installation reference](https://docs.astral.sh/uv/getting-started/installation/) documents installation choices. Installation commands change local software; on a shared machine obtain the machine owner's authorization first.
Now verify the tools:
docker version must show a server, not just a client. Connection errors mean the engine is stopped or your account lacks access. uv sync --frozen creates .venv using the supplied lock. It must exit successfully; do not delete the lock to suppress a dependency error. The resulting Python environment is used by the client snippets below.
For the native automated journey, additional native PostgreSQL commands and OpenSSL are required. On a Linux host with apt: apt-get install -y postgresql@17, then add $(brew --prefix postgresql@17)/bin to your PATH for this terminal. Do not start a global database service for that script; it manages private temporary instances. On a fresh Ubuntu 24.04 workstation, install its matching distribution server/client binaries:
The package installation may start Ubuntu's default database service. The journey script uses separately owned temporary clusters and free loopback ports; do not stop an existing service to make it run. Run the journey as your ordinary user, because initdb refuses root. Confirm initdb, pg_ctl, pg_dump and pg_restore resolve to the matching installation. Run the native journey from your Crucible VM workspace (~/playground) using the example environment:
Expected: a current proof/reference-journey.json with passed stages and owned cleanup. Read its limitations. It creates ephemeral credentials and private data, so it does not leave an interactive database for the rest of this tutorial. A missing prerequisite is a setup failure, not a passed lifecycle check.
3. Define the lab and generate configuration
Our contract is bounded text submission, durable job identity, eventual result and tenant isolation. The API returns 202 before the worker completes. The initial deployment is one host, with no high-availability promise. We will demonstrate recovery of the last logical backup; work committed afterward can be lost. Use synthetic text only.
Create generated secrets once:
The setup program exclusively creates .env with private permissions. A second invocation refuses an existing file. Preserve it and inspect which lab owns it; do not overwrite it. Source only this locally generated file you trust: sourcing a shell file executes shell syntax. .recovery stores private exercise state and must not be committed or included in a shared report.
The generated variables have specific uses. LAB_TOKEN is the initial tenant-admin client token. API_KEYS_JSON seeds that token into the database. APP_DB_PASSWORD belongs to restricted runtime role lab_app; POSTGRES_PASSWORD belongs to migration/administration role lab_owner. MONITOR_TOKEN protects metrics; WEBHOOK_SECRET authenticates the custom demo webhook. Compose constructs its PostgreSQL DATABASE_URL internally. The generated host DATABASE_URL=sqlite:///jobs.db is for introductory host execution and is not what the containers use. Do not run host worker.py against it while assuming it processes the container database.
4. Provision, migrate and start the complete stack
First validate without expanding secrets into terminal output:
Expected: db, api and worker run; roleinit, init and seed finish successfully; readiness returns a successful response. The chain creates a dedicated volume, creates lab_app, migrates as lab_owner, then seeds the bootstrap credential. API/worker use runtime DML rights. No PostgreSQL host port is published; the API binds only127.0.0.1:18768.
If startup fails, inspect docker compose logs --tail 80 db roleinit init seed api worker. Read the first causal error. A no-space error requires capacity investigation; never run a broad prune or delete unrelated volumes. An Alembic failure requires the matching schema and migration log, not repeated initialization against guessed databases. A port-in-use error requires identifying the listener and selecting a reviewed alternate binding consistently in clients and proxy configuration.
Confirm restricted identity through the service rather than assuming a role name is sufficient. The current native PostgreSQL receipt separately checks denied runtime DDL. Container administrators can inspect environment secrets; the lab assumes the workstation and Docker administrator are trusted.
5. Submit, read and test denial from a real client
Run this host client. It reads the disposable token from your environment, avoiding a literal token in command history:
A202 response means the job was committed, not that its handler finished. A401 without credentials and 409 for changed input are expected. Do not interpret those expected test errors as broken service. A successful first response followed by indefinitely queued work directs investigation toward the worker and its database connection.
Now restart only the application processes and read the same result:
For a database restart test, execute this exact maintenance sequence and read the same saved job:
Record the interruption. This is a maintenance exercise, not zero downtime. The persistent named volume must retain the result. If you selected compose.ephemeral.yaml, you selected volatile storage and cannot claim this persistence result.
6. Diagnose a stopped worker and recover it
Read the new job and require queued status while the worker is stopped, then start the worker and poll that exact ID:
The API can be ready while no worker is consuming jobs; this is why queue-age monitoring matters. Preserve that initial symptom and recovery duration in the notebook.
Tutorial04 contains the complete local/remote Prometheus and Alertmanager install, protected scrape, receiver, fault and recovery-notification sequence. Follow that sequence against this same service; retain its firing/resolved delivery record. For the current service, prove metrics are protected: an unauthenticated GET /metrics must fail. Store MONITOR_TOKEN in the scraper's protected credential file, not a dashboard URL. Installing the supplied dashboard does not establish operational coverage until scrape, threshold, receiver and recovery notification are exercised.
7. Create an encrypted backup and restore a separate database
Begin only after the synthetic jobs are complete. A logical backup is consistent as a database snapshot, but external files or side effects require coordinated backup rules. Stop writers for this exercise so the recovery point is unambiguous:
Expected: every command exits0 and cmp emits no difference. The plaintext dumps and private identity are deliberately retained only in a restrictive disposable exercise directory. Real operational pipelines should stream encryption, minimize plaintext lifetime and keep the recovery identity separately from the host and encrypted archive. Anyone who obtains both this directory and identity can decrypt the fixture. Test a copy with corruption and expect decryption failure; never corrupt the only backup.
Create a new, specifically named database. If it already exists, stop and choose a new name consistently; never drop an unknown database to force the tutorial to run:
This restore uses the same cluster and existing roles. It proves a separate dataset, not loss of the workstation. A fresh-host exercise must recreate roles, recover keys independently and restore using compatible clients. The dump contains credential records and should be protected accordingly. Consult [pg_restore](https://www.postgresql.org/docs/current/app-pgrestore.html) before adapting ownership, role or schema options.
Create this complete override as compose.recovery.yaml in the example directory:
Then switch application processes to that recovered dataset:
Repeat the saved-job reader from step5. It must retrieve the original completed result through the API. Submit the first request again with the same key and input and require the original ID. Save record counts and representative results. These checks distinguish recovery from merely loading a file. To return to the original lab database, stop writers and run the baseline docker compose up -d --no-deps --wait api worker. Record which dataset is now authoritative before accepting further writes.
8. Change, rotate and maintain deliberately
Do not edit live code in a running container. Tutorial03 builds and transfers a reviewed artifact and retains the previous artifact. On a compatible schema, a rollback restores the previous application image; an incompatible schema may need a forward fix or separate-database recovery. The supplied release helper validates an immutable repository digest and performs a maintenance stop/migrate/start sequence. It requires a real digest already present on the selected local Docker daemon; a local image ID and a registry manifest digest are different identities.
For credential rotation, execute this complete issue/use/revoke cycle. It tests a disposable read-only credential while retaining the working admin path:
The077 umask keeps the issued secret file private. The endpoint returns token material once; never paste the token into a shared notebook.
For a complete replacement of this lab's bootstrap credential, first record its exact ID through the authorized operator's database access. The token itself remains an environment value, not a command argument:
On Ubuntu without Docker-group access, use sudo --preserve-env=LAB_TOKEN docker compose exec ... for that one command so the generated test token is deliberately passed through sudo. Do not grant unrestricted environment preservation. Then execute the replacement client:
The replacement is a one-day lab credential; production rotation needs the approved expiry/renewal policy. Its private recovery record is saved before revocation, so an environment-file update failure does not erase the new admin path. The script updates the known lab configuration atomically and records old-token denial. A second run rotates the currently configured token, not an already revoked historical token. Human-account login and disable remain a separate lifecycle.
Daily operation checks user-visible completion, queue age, failed jobs, disk/inodes, backup freshness and alert delivery. Patching begins in staging with the same artifact and restored data, then follows an agreed maintenance window and recovery plan. operator_cli.py maintain --days 90 deletes old terminal jobs and expired records; choose retention before scheduling it. Retention also defines how long an old request key remains remembered.
9. Retire the lab without harming neighbors
First export the final redacted evidence and decide whether any backup must remain. Stop new clients and schedules. Allow accepted work to complete or document which jobs will not complete. Verify the final backup is usable before removing access or storage. Record the exact project, containers, volume and retained archive.
down stops/removes this Compose project's containers and network while preserving its named database volume. Check that /health/live on 18768 no longer connects. Inspect the exact volume using docker volume inspect server-mastery-v5-lab_pgdata; this command does not delete it. Record its owner and retention decision. Neither a silent command nor an empty container list proves that every disk or billable resource is gone.
If—and only if—you have confirmed this exact volume belongs to this disposable lab and have approved permanent data deletion, docker volume rm server-mastery-v5-lab_pgdata removes that one volume. Docker refuses a volume still in use. Do not substitute a broad prune, wildcard or guessed volume name. Keep private .env, backups and keys according to the chosen retention policy, or remove only their explicitly reviewed files after the exercise. Stop unrelated services only through their own operational procedures.
Troubleshooting, recovery and independent assessment
Use the failure library for symptom-specific branches. Begin with target and identity: correct host, directory, Compose project, database, token and release. Then inspect DNS/TCP/TLS, readiness, API identity, committed job, worker state and database limits in order. Preserve the first error and avoid several speculative changes at once. Retry only when the operation's idempotency and upstream completion rules permit it.
You pass this walkthrough when you can repeat it with fresh synthetic inputs, explain each status and identity, recover the stopped worker, restore the saved job through the recovered database, reject a scoped credential after revocation, and retire only the intended resources. Another operator should be able to identify the authoritative dataset and recover it from your redacted record. Public HTTPS, actual remote reboot recovery, offsite key recovery and production load remain separate acceptance tasks in tutorial02 and the platform tracks.