Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Add or update tests when behavior changes, especially for server routes, databas
- **`APPX_DATA` holds only the DB and TLS certs** (`.appx-internals/`). Project files live in the `builder-workspace` Docker volume under Docker's data-root — mounting a volume at `APPX_DATA` gives projects no capacity. There is deliberately no host `$APPX_DATA/projects` and no shared `projects` group: in container mode appx creates no project files at all, so `hostProjectRoot` returns `""` and `Manager.ProjectDir` reports no host path. The project terminal therefore execs into the outer container rather than opening a host shell; `APPX_PROJECT_SHELL_CONTAINER` forces that path outside container mode (local dev against a hand-run agent-server container).
- The agent (agent-server + Pi) runs as an unprivileged uid **inside** the outer container, not as a host user; provider secrets reach it via the service env (`/etc/appx/secrets.env`, `root:root 0600`), forwarded into the container by name.
- The Docker daemon (`--restart unless-stopped`) keeps the outer container alive across crash + reboot; appx's startup `EnsureRunning` re-attaches idempotently (never auto-recreates on drift). `appx.service` is ordered `After=docker.service`.
- `deploy/teardown.sh` always removes the outer container (a process — `--restart unless-stopped` would otherwise keep the agent running after appx is gone; appx recreates it from the volumes). `--purge-data` additionally removes `builder-workspace` and `builder-podman-storage`, which is where **all** project data lives — purging only `APPX_DATA` would leave every project behind and let a later bootstrap inherit the old workspace. Container and volume names are read from `appx.env` before it is deleted, so a renamed deployment is not skipped.
- `appx` is in the `docker` group (root-equivalent — accepted on a dedicated box; Stage 5 scopes it down). It binds 443 via `CAP_NET_BIND_SERVICE`, not root.
- Provider traffic from Pi goes through the Appx egress proxy (bridge gateway in container mode); loopback traffic to agent-server stays local.
- The HSTS header includes `includeSubDomains`. Do not point appx at a shared domain that also hosts HTTP services on subdomains.
Expand Down
90 changes: 79 additions & 11 deletions deploy/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
# Must be run as root. Safe to run multiple times (idempotent).
#
# Shared build/runtime tools (go, node, pi, claude, uv) are intentionally left
# in place — they are not appx-specific. Pass --purge-data to also delete the
# data directory and the agent user's home (DESTRUCTIVE: removes all projects,
# the SQLite DB, TLS certs, and session transcripts).
# in place — they are not appx-specific.
#
# Pass --purge-data to also delete every piece of appx state (DESTRUCTIVE and
# IRREVERSIBLE):
# - the data directory (SQLite DB, TLS certs) and the legacy agent user's home
# - /etc/appx/secrets.env (provider credentials)
# - the outer container and BOTH of its named volumes: builder-workspace
# (every project's files and Pi session transcripts) and
# builder-podman-storage (inner app images and containers)
#
# The volumes are the part that is easy to miss: in container mode they, not the
# data directory, hold all project data, and nothing else in this script touches
# them. Without removing them, --purge-data leaves projects behind and a
# subsequent bootstrap silently inherits the old workspace.

set -euo pipefail

Expand All @@ -28,14 +39,23 @@ done

ENV_FILE="/etc/appx/appx.env"

# Resolve the data dir from the env file (fall back to the default) before we
# delete the env file.
# Resolve everything we need from the env file BEFORE deleting it. The container
# and volume names are overridable per deployment, so read them rather than
# assuming the defaults — otherwise --purge-data would silently skip a renamed
# container's volumes and leave all project data behind.
DATA_DIR="/var/lib/appx"
CONTAINER_NAME="builder-outer"
WORKSPACE_VOLUME="builder-workspace"
PODMAN_VOLUME="builder-podman-storage"
if [ -f "$ENV_FILE" ]; then
_APPX_DATA=$(grep '^APPX_DATA=' "$ENV_FILE" | cut -d= -f2- || true)
if [ -n "$_APPX_DATA" ]; then
DATA_DIR="${_APPX_DATA%/}"
fi
[ -n "$_APPX_DATA" ] && DATA_DIR="${_APPX_DATA%/}"
_CNAME=$(grep '^APPX_AGENT_CONTAINER_NAME=' "$ENV_FILE" | cut -d= -f2- || true)
[ -n "$_CNAME" ] && CONTAINER_NAME="$_CNAME"
_WSVOL=$(grep '^APPX_AGENT_WORKSPACE_VOLUME=' "$ENV_FILE" | cut -d= -f2- || true)
[ -n "$_WSVOL" ] && WORKSPACE_VOLUME="$_WSVOL"
_PDVOL=$(grep '^APPX_AGENT_PODMAN_VOLUME=' "$ENV_FILE" | cut -d= -f2- || true)
[ -n "$_PDVOL" ] && PODMAN_VOLUME="$_PDVOL"
fi

# ---------------------------------------------------------------------------
Expand All @@ -56,14 +76,34 @@ pkill -u appx-agent -f '(^|/)agent-server( |$)|agent-server/dist/server\.js' 2>/
pkill -u appx -f '(^|/)appx( |$)' 2>/dev/null || true

# ---------------------------------------------------------------------------
# 2. Binaries
# 2. Outer agent container
# ---------------------------------------------------------------------------

# The container runs with `--restart unless-stopped`, so the Docker daemon keeps
# it (and the agent inside it) alive and brings it back on reboot even after the
# appx service is gone. Remove it unconditionally: it is a process, not data —
# its state lives in the named volumes, which survive here and are only deleted
# under --purge-data below. appx's EnsureRunning recreates it on next startup.
if command -v docker >/dev/null 2>&1; then
if docker inspect "$CONTAINER_NAME" >/dev/null 2>&1; then
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
echo "removed outer container: $CONTAINER_NAME (volumes kept)"
else
echo "no outer container named $CONTAINER_NAME"
fi
else
echo "docker not installed — skipping outer container removal"
fi

# ---------------------------------------------------------------------------
# 3. Binaries
# ---------------------------------------------------------------------------

rm -f /usr/local/bin/appx /usr/local/bin/agent-server /usr/local/bin/opencode
echo "removed binaries: /usr/local/bin/{appx,agent-server,opencode}"

# ---------------------------------------------------------------------------
# 3. Users and groups
# 4. Users and groups
# ---------------------------------------------------------------------------

# userdel -r would remove home dirs; we manage data deletion explicitly below so
Expand All @@ -83,7 +123,7 @@ for grp in projects appx-agent; do
done

# ---------------------------------------------------------------------------
# 4. Config + data
# 5. Config + data
# ---------------------------------------------------------------------------

rm -f "$ENV_FILE"
Expand All @@ -108,5 +148,33 @@ else
echo "kept data: $DATA_DIR and /home/appx-agent (re-run with --purge-data to delete)"
fi

# The named volumes, NOT the data directory, hold all project data in container
# mode: builder-workspace has every project's files and Pi session transcripts,
# builder-podman-storage has the inner app images. They are removable only now
# that the container referencing them is gone (section 2) — `docker volume rm`
# refuses while a container still uses it.
if [ "$PURGE_DATA" -eq 1 ]; then
if command -v docker >/dev/null 2>&1; then
for vol in "$WORKSPACE_VOLUME" "$PODMAN_VOLUME"; do
if docker volume inspect "$vol" >/dev/null 2>&1; then
if docker volume rm "$vol" >/dev/null 2>&1; then
echo "purged volume: $vol"
else
# Almost always another container still mounting it.
echo "WARNING: could not remove volume $vol — still in use?" >&2
echo " inspect with: docker ps -a --filter volume=$vol" >&2
fi
else
echo "no volume named $vol"
fi
done
else
echo "WARNING: docker not installed — project data in the named volumes was NOT purged" >&2
fi
else
echo "kept volumes: $WORKSPACE_VOLUME and $PODMAN_VOLUME (ALL project files and"
echo " sessions live here, not in $DATA_DIR; --purge-data deletes them)"
fi

echo ""
echo "Teardown complete. Shared tools (go, node, pi, claude, uv) were left in place."
21 changes: 20 additions & 1 deletion docs/readme/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,23 @@ docker logs -f builder-outer # agent-server (inside the outer container)
| `deploy/agent-version.sh` | sourced, not run | Resolves `AGENT_VERSION` → `$AGENT_IMAGE` for the other scripts |
| `deploy/appx.service` | systemd unit | `appx` unit (container mode; ordered after `docker.service`) |
| `deploy/verify-installation.sh` | After any change | Full system verification |
| `deploy/teardown.sh` | Uninstall & cleanup | Reverse everything created by bootstrap.sh |
| `deploy/teardown.sh` | Uninstall & cleanup | Reverse everything created by bootstrap.sh (see below) |

### Uninstalling

```bash
sudo ./deploy/teardown.sh # keep all data
sudo ./deploy/teardown.sh --purge-data # DESTRUCTIVE: delete everything
```

Both remove the services, binaries, users, config, and the **outer container** —
the container runs with `--restart unless-stopped`, so leaving it would keep the
agent alive and restarting after appx is gone. Removing it is safe: its state is
in the named volumes, and appx recreates the container on next start.

`--purge-data` additionally deletes the data directory *and* both named volumes:
`builder-workspace` (every project's files and Pi session transcripts) and
`builder-podman-storage` (inner app images). **This is where all project data
lives** — a purge that spared the volumes would leave every project behind and a
later bootstrap would silently inherit the old workspace. There is no undo, and
no backup is taken.
Loading