diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md deleted file mode 100644 index e9dcfce8..00000000 --- a/DOCUMENTATION.md +++ /dev/null @@ -1,33 +0,0 @@ -# Session documentation - -Decisions and changes made during development. - -## 2026-03-09: Run at boot and auth token re-sync - -### Goal - -- Allow Mission Control (local install, no Docker, e.g. in a VM) to run at boot via systemd (Linux) or launchd (macOS). -- Document how to re-sync auth tokens between Mission Control and OpenClaw when they have drifted. - -### Implemented - -1. **Systemd unit files** (`docs/deployment/systemd/`) - - Added example units: `openclaw-mission-control-backend.service`, `openclaw-mission-control-frontend.service`, `openclaw-mission-control-rq-worker.service`. - - Units use placeholders `REPO_ROOT`, `BACKEND_PORT`, `FRONTEND_PORT`; install instructions and a small README explain substitution and install to `~/.config/systemd/user/` or `/etc/systemd/system/`. - - RQ worker is required for gateway lifecycle and webhooks; it is a separate unit. - -2. **Deployment docs** (`docs/deployment/README.md`) - - Replaced placeholder with a short deployment guide. - - "Run at boot (local install)": Linux (systemd) with link to `systemd/README.md`; macOS (launchd) with example plist and `launchctl load`; Docker Compose note for `restart: unless-stopped`. - -3. **Troubleshooting** (`docs/troubleshooting/gateway-agent-provisioning.md`) - - New subsection "Re-syncing auth tokens when Mission Control and OpenClaw have drifted": when tokens drift, run template sync with `rotate_tokens=true` via API (curl) or CLI (`scripts/sync_gateway_templates.py --rotate-tokens`); after sync, wake/update gateway if needed. - -4. **install.sh** (`install.sh`) - - New optional flag `--install-service` (local mode only): on Linux, copies the three systemd unit files from `docs/deployment/systemd/`, substitutes `REPO_ROOT`/ports, installs to `$XDG_CONFIG_HOME/systemd/user` (or `~/.config/systemd/user`), runs `systemctl --user daemon-reload` and `systemctl --user enable`. On non-Linux, prints a note pointing to `docs/deployment/README.md` for launchd. Not prompted by default; only when the user passes `--install-service`. - -### Rationale - -- **No Docker in VM**: User runs local install in a VM and does not want Docker there; run-at-boot is provided by the OS (systemd/launchd). -- **Units as examples**: Units are in `docs/deployment/systemd/` so they can be versioned and copied; install.sh only installs when `--install-service` is given to avoid touching system/LaunchAgents without explicit opt-in. -- **Auth re-sync**: Token drift is a common failure mode; documenting the API and CLI with `rotate_tokens=true` in the provisioning troubleshooting doc makes recovery easy to find. diff --git a/docs/deployment/README.md b/docs/deployment/README.md index 951adce9..d6e1f372 100644 --- a/docs/deployment/README.md +++ b/docs/deployment/README.md @@ -131,7 +131,7 @@ The RQ queue worker is required for gateway lifecycle (wake/check-in) and webhoo ### macOS (launchd) -Use LaunchAgents so the backend, frontend, and worker run under your user and restart on failure. +LaunchAgents run at **user login**, not at machine boot. Use LaunchAgents so the backend, frontend, and worker run under your user and restart on failure. For true boot-time startup you would need LaunchDaemons or other configuration (not covered here). 1. Create a plist for each process under `~/Library/LaunchAgents/`, e.g. `com.openclaw.mission-control.backend.plist`: diff --git a/docs/deployment/systemd/README.md b/docs/deployment/systemd/README.md index 07f83f3a..b7a55666 100644 --- a/docs/deployment/systemd/README.md +++ b/docs/deployment/systemd/README.md @@ -14,7 +14,7 @@ If you use Docker only for Postgres and/or Redis, start those first (e.g. `docke Before installing, replace in each unit file: -- `REPO_ROOT` — absolute path to the Mission Control repo (e.g. `/home/user/openclaw-mission-control`). +- `REPO_ROOT` — absolute path to the Mission Control repo (e.g. `/home/user/openclaw-mission-control`). Must not contain spaces (systemd unit values do not support shell-style quoting). - `BACKEND_PORT` — backend port (default `8000`). - `FRONTEND_PORT` — frontend port (default `3000`). @@ -24,11 +24,13 @@ Example (from repo root): REPO_ROOT="$(pwd)" for f in docs/deployment/systemd/openclaw-mission-control-*.service; do sed -e "s|REPO_ROOT|$REPO_ROOT|g" -e "s|BACKEND_PORT|8000|g" -e "s|FRONTEND_PORT|3000|g" "$f" \ - -o "$(basename "$f")" + > "$(basename "$f")" done # Then copy the generated .service files to ~/.config/systemd/user/ or /etc/systemd/system/ ``` +**User units** start at **user login** by default. To have services start at **machine boot** without logging in, enable lingering for your user: `loginctl enable-linger $USER`. Alternatively, use system-wide units in `/etc/systemd/system/` (see below). + ## Install and enable **User units** (recommended for single-user / VM): diff --git a/install.sh b/install.sh index 838b441d..0f5cf913 100755 --- a/install.sh +++ b/install.sh @@ -3,13 +3,7 @@ set -euo pipefail SCRIPT_NAME="$(basename "$0")" -if [[ "$SCRIPT_NAME" == "bash" || "$SCRIPT_NAME" == "-bash" ]]; then - SCRIPT_NAME="install.sh" -fi -REPO_ROOT="" -REPO_GIT_URL="${OPENCLAW_REPO_URL:-https://github.com/abhi1693/openclaw-mission-control.git}" -REPO_CLONE_REF="${OPENCLAW_REPO_REF:-}" -REPO_DIR_NAME="openclaw-mission-control" +REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}" LOG_DIR="$STATE_DIR/openclaw-mission-control-install" @@ -57,66 +51,6 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } -repo_has_layout() { - local dir="$1" - [[ -f "$dir/Makefile" && -f "$dir/compose.yml" ]] -} - -resolve_script_directory() { - local script_source="" - local script_dir="" - - if [[ -n "${BASH_SOURCE:-}" && -n "${BASH_SOURCE[0]:-}" ]]; then - script_source="${BASH_SOURCE[0]}" - elif [[ -n "${0:-}" && "${0:-}" != "bash" ]]; then - script_source="$0" - fi - - [[ -n "$script_source" ]] || return 1 - - script_dir="$(cd -- "$(dirname -- "$script_source")" 2>/dev/null && pwd -P)" || return 1 - printf '%s\n' "$script_dir" -} - -bootstrap_repo_checkout() { - local target_dir="$PWD/$REPO_DIR_NAME" - - if ! command_exists git; then - die "Git is required for one-line bootstrap installs. Install git and re-run." - fi - if [[ -e "$target_dir" ]]; then - die "Cannot auto-clone into $target_dir because it already exists. Run ./install.sh from that repository or remove the directory." - fi - - info "Repository checkout not found. Cloning into $target_dir ..." - if [[ -n "$REPO_CLONE_REF" ]]; then - git clone --depth 1 --branch "$REPO_CLONE_REF" "$REPO_GIT_URL" "$target_dir" - else - git clone --depth 1 "$REPO_GIT_URL" "$target_dir" - fi - - REPO_ROOT="$target_dir" - SCRIPT_NAME="install.sh" -} - -resolve_repo_root() { - local script_dir="" - - if script_dir="$(resolve_script_directory)"; then - if repo_has_layout "$script_dir"; then - REPO_ROOT="$script_dir" - return - fi - fi - - if repo_has_layout "$PWD"; then - REPO_ROOT="$PWD" - return - fi - - bootstrap_repo_checkout -} - usage() { cat <