# Moving a systemd install to a container This runbook moves a running systemd install (see Production install in [operations.md](operations.md)) to the container image (see Running in a container). It was rehearsed with rootless Docker on a copy of a production database, with the network disabled and the pipeline off. Placeholders: `` is the systemd install root, `IMAGE` the image, `DATA` and `CONFIG` the volumes mounted at `/data` and `/config`. The `docker run` lines show the shared options as `$RUN`: ``` RUN="-v DATA:/data -v CONFIG:/config --env-file container.env" ``` `container.env` holds `AUTOCRAFT_BASE_URL`, `AUTOCRAFT_TRUST_PROXY` and any other setting from the systemd settings file that is not a path. Do not copy the path settings (`AUTOCRAFT_DB`, `AUTOCRAFT_SECRETS_FILE`, cache and lock directories, listen addresses): the image sets them. Go through the old settings file line by line: | Old setting | In the container | |---|---| | `AUTOCRAFT_BASE_URL`, `AUTOCRAFT_TRUST_PROXY`, `AUTOCRAFT_REVIEW_BOTS`, `AUTOCRAFT_STOP_TIMEOUT` | Copy to `container.env`. | | `AUTOCRAFT_DISCORD_TOKEN_FILE`, `AUTOCRAFT_DISCORD_KEY_FILE`, `AUTOCRAFT_IMAGE_TOKEN_FILE` | Each names a file. Copy the file to `/config` (step 6) and set the variable to the new path. | | `AUTOCRAFT_ARTIFACT_DIR`, `AUTOCRAFT_SNAPSHOT_DIR` | Leave unset: the code then uses `artifacts` and `item-snapshot` beside the database, in `/data` (step 5). | | `AUTOCRAFT_MERGE_CMD`, `AUTOCRAFT_EXTRA_STEPS` | Name a program or module of the old host. The image has neither; leave them unset unless a derived image adds it. | | `AUTOCRAFT_WORKER_SSH`, `AUTOCRAFT_BRANCH`, `AUTOCRAFT_ROOT`, `AUTOCRAFT_UNITS`, `AUTOCRAFT_RUNNER_UNIT`, `AUTOCRAFT_TIMER`, `AUTOCRAFT_SUDO`, `AUTOCRAFT_HEALTH_URL`, `AUTOCRAFT_ENV_FILE`, `AUTOCRAFT_KEEP_RELEASES` | Drop. Only `deploy/hook.sh` reads them; it runs `autocraft worker update-code`, which needs `ssh` and a bare repository, and the image has neither. Update a worker's code by hand (see Build worker in the VPS section). | Also check the old `PATH` for wrappers (for example a `gh` wrapper that picks an account by directory): the image has the plain `gh`, which uses the one `GH_TOKEN`. Steps marked **admin** need a person with access to the secrets or to DNS and the proxy. ## Before the window 1. **admin**: Build or pull the image and start it once with `--network none` against an empty volume to check that it runs (`IMAGE pipeline status`). 2. **admin**: Decide where the dashboard is reachable and keep the DNS and reverse-proxy change ready. `AUTOCRAFT_BASE_URL` must be the public origin; the GitHub App's callback and setup URLs and the OAuth app's callback URL must match it (see Moving to a new domain in [deploy-checklist.md](deploy-checklist.md)). 3. Check the free space of the target volume: the database plus its newest backup (a 1.2 GB database restored in under 10 s). 4. **admin**: Size the VPS disk. Plan for 20 GB or more (today's figures): | Part | Size | |---|---| | Database | 1.5 GB | | `reference/` | 1.5 GB (twice while an import runs) | | Item snapshot | 0.9 GB | | 7 daily backups | about 3.5 GB | | Checkouts (regrow after the move) | about 8 GB | | Fixup git cache (regrows) | about 3 GB | | Image, Docker layers and logs | a few GB | ## Cut-over 1. **Pipeline off.** On the old host: `autocraft pipeline off`. Wait until the runner has no running job (`autocraft pipeline status`, or the jobs list on the dashboard). `pipeline off` holds only automatic jobs: jobs queued by a user or the CLI stay queued and would start on the new runner. List them with `autocraft runner jobs --state queued` and cancel each with `autocraft runner cancel `. Check that the list is empty before the final backup. Also check that `worker_update_pending` is not set: `autocraft worker status` lists a pending update. A pending update makes the runner call `ssh`, which the image does not have (`src/build/worker-update.ts:119-142`); finish it on the old host first. 2. **Final backup.** `deploy/backup.sh predeploy` (with the systemd settings loaded). It writes `/backups/predeploy-.db.zst` from a consistent snapshot and checks its integrity. Keep the file name. 3. **Stop the old services**: the runner, the dashboard, the sync and backup timers. Nothing may write to the old database from now on. Do not delete anything on the old host. 4. **Create the volumes** and make `/data` and `/config` writable by uid 10001. With Docker, named volumes take that ownership from the image. In Kubernetes, `fsGroup: 10001` does it. 5. **Restore the database** into the data volume. Stream the backup through a container so no host permissions are involved (the volume belongs to uid 10001, and under rootless Docker the host cannot read it): ``` zstd -dc predeploy-