From 2d564a15465b83b776eadcf61f8c76433673627b Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 22 Nov 2026 22:57:53 +0200 Subject: [PATCH] add uninstall steps --- README.md | 4 + UNINSTALL.md | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100755 UNINSTALL.md diff --git a/README.md b/README.md index 5f7375b..90e4252 100755 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ python3 -m proxdomain --help The only runtime dependency is the Python standard library, so copying the folder and running `python3 -m proxdomain` also works. +To remove proxdomain again — domains, DNS records, include line and secrets — +follow [`UNINSTALL.md`](UNINSTALL.md). + ## Credentials ### Proxmox API token @@ -365,6 +368,7 @@ proxdomain/ state.py state.json, locking, audit log tests/ test suite against fake HTTP/SSH layers deploy/ systemd units and a sudoers example +UNINSTALL.md step-by-step removal runbook ``` ## Development diff --git a/UNINSTALL.md b/UNINSTALL.md new file mode 100755 index 0000000..4a67693 --- /dev/null +++ b/UNINSTALL.md @@ -0,0 +1,298 @@ +# Uninstalling proxdomain + +proxdomain has no `uninstall` subcommand: removal is a short sequence of explicit +steps. **Order matters** — the domains must be released *before* the config and +the API tokens are deleted, because `proxdomain remove` is what deletes the +Cloudflare records for you. + +What proxdomain created, and what it only borrowed: + +| Created by proxdomain | Borrowed (leave it alone) | +| --- | --- | +| One vhost file per domain in `webserver.manage_dir` | nginx / Caddy / Traefik itself | +| The `A`/`AAAA` record for each managed domain | Your Cloudflare zone | +| `state.json`, `audit.jsonl`, `state.json.lock` | The Proxmox guests | +| The one-time include line added by `proxdomain init` | `/etc/letsencrypt` (unless proxdomain issued it) | +| `/etc/proxdomain/{config.toml,env}` | | + +Uninstalling proxdomain must therefore never damage the web server, the zone or +the guests. + +--- + +## TL;DR (Caddy on the Proxmox host) + +```bash +systemctl disable --now proxdomain-watch.timer 2>/dev/null +proxdomain remove --fqdn sftpgo.bbnn.me --yes # repeat for every managed domain +# edit /etc/caddy/Caddyfile: drop "# proxdomain managed sites" + the import line +rm -f /etc/caddy/conf.d/*.caddy && rmdir /etc/caddy/conf.d 2>/dev/null +rm -rf /etc/proxdomain /var/lib/proxdomain /opt/proxdomain +rm -f /usr/local/bin/proxdomain +``` + +The sections below explain each step, with the nginx and Traefik variants. + +--- + +## 1. Take inventory first + +```bash +proxdomain list # managed domains (this is your removal list) +proxdomain list --json # same, machine readable +proxdomain doctor # where the config actually lives, which web server +``` + +`doctor` prints the resolved config path, the web server kind, the managed +directory and the state file. If it is already broken, read the paths from the +config instead: + +```bash +grep -E '^\s*(path|audit_path|manage_dir|kind)\s*=' /etc/proxdomain/config.toml +echo "$PROXDOMAIN_CONFIG" # the systemd unit sets this explicitly +``` + +Keep the output: the paths in the rest of this document are the defaults. + +## 2. Stop the automation + +Only needed if you installed the timer/cron job. + +```bash +systemctl list-timers | grep proxdomain # is anything scheduled? +systemctl disable --now proxdomain-watch.timer +systemctl stop proxdomain-watch.service + +rm -f /etc/systemd/system/proxdomain-watch.service +rm -f /etc/systemd/system/proxdomain-watch.timer +systemctl daemon-reload +``` + +The units are the files from [`deploy/`](deploy/): +`proxdomain-watch.service` runs `watch --once --auto-assign` every two minutes. + +* **cron:** `crontab -l | grep proxdomain` then remove that line with `crontab -e`. +* **long-running `proxdomain watch`** in tmux/screen or another unit: stop that + process too (`pgrep -af proxdomain`). + +If you only want to *pause* automatic assignment, stop here and skip the rest: +`systemctl disable --now proxdomain-watch.timer` keeps every existing domain, +vhost and DNS record working. + +## 3. Release every managed domain + +`remove` deletes the vhost file, the Cloudflare record and the state entry in one +go. It needs `--yes`; `--dry-run` shows the plan without touching anything. + +```bash +# preview one +proxdomain remove --fqdn sftpgo.bbnn.me --dry-run + +# then for real, one at a time +proxdomain remove --fqdn sftpgo.bbnn.me --yes + +# or by guest id +proxdomain remove --vmid 101 --yes + +# or everything in bulk (python3 ships with Proxmox VE) +proxdomain list --json \ + | python3 -c 'import json,sys; [print(a["fqdn"]) for a in json.load(sys.stdin)]' \ + | while read -r name; do proxdomain remove --fqdn "$name" --yes; done +``` + +Verify that nothing is left: + +```bash +proxdomain list # expect: no managed domains yet +``` + +Notes: + +* Records you created by hand in the Cloudflare dashboard are not tracked and + must be deleted there. +* `remove` takes the record id from the state file, so run this **before** + deleting `state.json` and before revoking the Cloudflare token. +* `remove` does not delete issued certificates — see step 6. +* A DNS failure during `remove` still deletes the vhost, keeps the entry in + `state.json` and exits non-zero. Fix the cause (expired token, record already + deleted by hand) and run the same `remove` again; it is idempotent. + +## 4. Undo `proxdomain init` + +`init` added exactly one include/import line so the web server would read the +managed directory. Nothing else in your web server configuration was touched. + +### Caddy + +`/etc/caddy/Caddyfile` ends with a block that proxdomain appended: + +```caddyfile +# proxdomain managed sites +import /etc/caddy/conf.d/*.caddy +``` + +Delete those two lines (and the blank line before them), then: + +```bash +caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile +systemctl reload caddy +``` + +Then remove the directory — **only if it holds no site of your own**: + +```bash +ls /etc/caddy/conf.d/ +rm -rf /etc/caddy/conf.d +``` + +A non-default `webserver.manage_dir` changes both the import line and the +directory name; use what `doctor` printed. + +### nginx + +```bash +cat /etc/nginx/conf.d/proxdomain.d.conf +``` + +It contains the include line, preceded by a one-line comment: + +```nginx +# Managed by proxdomain: pulls in generated virtual hosts. +include /etc/nginx/conf.d/proxdomain.d/*.conf; +``` + +```bash +rm -f /etc/nginx/conf.d/proxdomain.d.conf +rm -rf /etc/nginx/conf.d/proxdomain.d # again: only if nothing else lives there +nginx -t && systemctl reload nginx +``` + +If `init` printed a `note` instead of writing the file (because `manage_dir` was +not inside a `conf.d` directory), you added the `include` line to the `http {}` +block by hand — remove it there. + +### Traefik + +The file provider watches a directory; proxdomain wrote one `.yml` per domain +into it (default `/etc/traefik/dynamic`). Removing the domains in step 3 already +deleted those files. If you added the `providers.file` block to the static config +solely for proxdomain, remove it and restart Traefik. + +## 5. Delete the application, its data and its secrets + +```bash +# --- the installed package (venv + console script) --- +/opt/proxdomain/.venv/bin/pip uninstall -y proxdomain +rm -f /usr/local/bin/proxdomain +rm -rf /opt/proxdomain + +# --- configuration and API tokens --- +rm -rf /etc/proxdomain # config.toml, env (PVE + Cloudflare secrets) + +# --- state, lock file, audit log --- +rm -rf /var/lib/proxdomain # state.json, state.json.lock, audit.jsonl +``` + +Adjust the paths if `state.path` / `state.audit_path` / `--config` point +elsewhere. + +* Installed for one user only (`pip install --user`)? Use + `python3 -m pip uninstall -y proxdomain` and delete `~/.local/bin/proxdomain`. +* Ran straight from a checkout (`python3 -m proxdomain`, no venv)? There is + nothing to uninstall — delete the checkout directory. +* `webserver.mode = "ssh"` from another machine? On the *client* delete the + checkout and, if it was dedicated to proxdomain, the key in + `webserver.ssh_identity_file`. On the *remote host* run steps 3–5. +* Did you install the sudoers rule from + [`deploy/sudoers.example`](deploy/sudoers.example)? Remove it too, it is + root-equivalent: + +```bash +rm -f /etc/sudoers.d/proxdomain +visudo -c +``` + +* Added a logrotate rule for `audit.jsonl`? Remove it. + +## 6. Optional cleanup + +### Certificates issued by proxdomain + +With `webserver.tls.mode = "letsencrypt"` (or the older `certbot`) on nginx, +certificates stay in `/etc/letsencrypt` after `remove`, and certbot keeps +renewing them. + +```bash +certbot certificates # list what is left +certbot delete --cert-name sftpgo.bbnn.me # removes live/ + renewal/ entries +``` + +A wildcard or shared certificate used by other sites must be kept. + +The ACME webroot is only a directory: + +```bash +rmdir /var/www/certbot 2>/dev/null +``` + +### Credentials + +```bash +# Proxmox: the token (and the user, if proxdomain was its only purpose) +pveum user token remove automation@pve proxdomain +pveum user remove automation@pve + +# Cloudflare: delete the API token in the dashboard +# My Profile -> API Tokens -> Roll/Delete +``` + +Revoking the tokens last means every step above still works. If a token leaked +into a chat, log or shell history, revoke it even if you keep proxdomain +installed. + +## 7. Verify the removal + +```bash +command -v proxdomain || echo "not installed" +systemctl status proxdomain-watch.timer 2>&1 | head -1 # expect: could not be found + +dig +short sftpgo.bbnn.me # expect: empty +curl -sSI https://sftpgo.bbnn.me | head -1 # expect: connection failure + +ls /etc/proxdomain /var/lib/proxdomain 2>&1 # expect: No such file or directory +systemctl is-active caddy nginx 2>/dev/null # your web server must still be active +nginx -t 2>/dev/null; caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile 2>/dev/null +``` + +The last two commands matter most: the web server must be **healthy** after the +include line and the vhosts are gone. + +## Reference: files created by proxdomain + +| Path | What it is | Safe to delete | +| --- | --- | --- | +| `/opt/proxdomain/` | checkout + virtualenv | yes | +| `/usr/local/bin/proxdomain` | symlink to the venv console script | yes | +| `/etc/proxdomain/config.toml` | configuration | yes (contains no secrets) | +| `/etc/proxdomain/env` | PVE + Cloudflare tokens for systemd | yes | +| `/var/lib/proxdomain/state.json` | managed assignments | yes, after step 3 | +| `/var/lib/proxdomain/state.json.lock` | concurrency lock | yes, no process may be running | +| `/var/lib/proxdomain/audit.jsonl` | append-only action log | yes, keep a copy if you need the history | +| `/etc/nginx/conf.d/proxdomain.d/` | generated nginx vhosts | yes, after step 3 | +| `/etc/nginx/conf.d/proxdomain.d.conf` | `include` line added by `init` | yes | +| `/etc/caddy/conf.d/` | generated Caddy snippets | yes (keep the `import` line removal in sync) | +| `/etc/traefik/dynamic/` | generated Traefik file-provider YAML | yes | +| `/var/www/certbot/` | ACME HTTP-01 webroot | empty directory, safe | +| `/etc/letsencrypt/{live,renewal}/` | certificates | only via `certbot delete` | +| `/etc/systemd/system/proxdomain-watch.{service,timer}` | automation units | yes | +| `/etc/sudoers.d/proxdomain` | SSH-mode privilege rule | yes | + +## If something goes wrong + +| Symptom | Fix | +| --- | --- | +| `cannot load certificate` / nginx fails after deletion | A vhost still references a deleted certificate. Re-run step 3 for that domain, or restore the certificate with `certbot certonly --webroot -w /var/www/certbot -d `. | +| nginx/Caddy refuses to start after step 4 | The `include`/`import` line still points at a deleted directory. Remove the line, then `nginx -t` / `caddy validate`. | +| `state file is locked` | A proxdomain process is still running (`pgrep -af proxdomain`). Stop it; only then delete `state.json.lock`. | +| `remove` reports a DNS error | The record may already be gone. Check the dashboard, then delete the state entry by re-running `remove` once the API call succeeds. | +| Domain still resolves after `dig` | Cloudflare caches; wait for the record TTL, or check for a second record with the same name (`A` vs `AAAA`, or a wildcard). |