ZFC PANEL — AI AGENT INSTALL INSTRUCTIONS (llms-install.txt) ============================================================ You are an AI coding agent (Claude Code, Codex, etc.). A user has asked you to install or manage the ZFC panel for them. Follow these instructions exactly. This file is self-contained; the canonical contract is also at https://www.zeroforwarder.com/docs/agent-install/ and in the repo's AGENT_INSTALL.md. 你是一个 AI 编码助手。用户请你帮他安装/管理 ZFC 面板。请严格按本文件执行。 WHAT YOU NEED FROM THE USER (ask only if not already provided) -------------------------------------------------------------- For a fresh install you need 4 required values: WEB_DOMAIN frontend domain, e.g. forward.example.com CONTROLER_DOMAIN controller domain, e.g. zf-controler.example.com ZFC_INSTANCE_ID license instance id (from the ZFC provider) ZFC_API_KEY license api key (from the ZFC provider) Optional but recommended: CADDY_EMAIL (ACME email for cert expiry notices). Tell the user to first ensure BOTH domains have an A record pointing to the target server's public IP. If they use Cloudflare, both records must be "DNS only" (grey cloud), NOT proxied (orange cloud) — otherwise HTTPS will fail. WHERE TO RUN ------------ Run where you have a shell on the TARGET server: - On the VPS directly, or - Over SSH from the user's machine: ssh user@SERVER 'ENV... bash <(curl -sL https://get.zeroforwarder.com/install.sh) --install -y --json' Run as root (or with sudo) so missing dependencies can be auto-installed. STEP 1 — PRE-FLIGHT (no changes are made) ----------------------------------------- WEB_DOMAIN=... CONTROLER_DOMAIN=... ZFC_INSTANCE_ID=... ZFC_API_KEY=... \ bash <(curl -sL https://get.zeroforwarder.com/install.sh) --check --json Read the JSON: {"status":"ok|error","ready":true|false,"fatal":N,"warnings":[...],"hint":"..."}. If ready:false, fix each fatal item (most often: a domain that does not resolve, a busy port, or an existing install detected -> add --force/--clean-install, see RETRY below) and run --check again until ready:true. A "hint" field, when present, names the fix. Treat warnings as advice (e.g. Cloudflare orange-cloud / IP mismatch → ask the user to use grey cloud; low memory/disk; old Docker). STEP 2 — INSTALL ---------------- WEB_DOMAIN=... CONTROLER_DOMAIN=... ZFC_INSTANCE_ID=... ZFC_API_KEY=... \ CADDY_EMAIL=... \ bash <(curl -sL https://get.zeroforwarder.com/install.sh) --install -y --json The machine-readable result is the LAST stdout line AND the file .zfc_install_result.json (mode 600). Prefer reading the file. Success looks like: {"status":"success","action":"install","web_url":"https://WEB_DOMAIN", "controller_url":"https://CONTROLER_DOMAIN","admin_address":"admin@zfc.local", "admin_token":"","caddy_enabled":true,"warnings":[],"errors":[]} STEP 3 — VERIFY & REPORT ------------------------ docker compose ps # all services should be Up curl -I https://WEB_DOMAIN # should return 200/302 Then tell the user: - Login URL: https://WEB_DOMAIN - Admin address: admin@zfc.local - Admin token: EXIT CODES (branch on these) ---------------------------- 0 success 10 missing required input OR unmet precondition (e.g. --update with no install) 11 port conflict -> free the listed port, or use external DB / CADDY_ENABLED=false 12 dependency unavailable -> run as root or apt-install deps, then re-run 13 license invalid -> re-check ZFC_INSTANCE_ID / ZFC_API_KEY (no stray spaces) 14 database connect failed -> fix EXTERNAL_* credentials/reachability 15 admin create failed -> inspect controller/db logs, re-run 16 existing install (also: --force blocked on a suspected COMPLETE install) -> --update to keep data; --force/--clean-install to rebuild/wipe 17 bad config / unknown arg 18 schema migration failed/incomplete (--update) -> run --doctor; see UPDATE FAILURES below 19 post-update health gate failed (new containers did not stay up) -> --doctor, read logs 20 image pull failed (--update) -> check DOCKER_REGISTRY / network / credentials, retry 1 unexpected/internal failure (rare; read the JSON reason). Not a contract code. For --check, the exit code equals the FIRST fatal check's code. On any non-zero exit in --json mode you also get (stdout's last line + result file): {"status":"error","action":...,"code":N,"reason":"...","hint":""} The error JSON may include a "hint" with an actionable remediation string. OTHER ACTIONS (all support -y --json) ------------------------------------- --update update images, keep data --uninstall (env ZFC_UNINSTALL_MODE=1|2|3: 1 stop-only, 2 drop builtin-db data, 3 full wipe) --show-token returns {"admin_token":"..."} --refresh-token rotate admin token --pack create a migration tarball --restore (env ZFC_RESTORE_PACKAGE=) --doctor read-only diagnosis of a running/broken deploy (JSON) --clean-install wipe local volumes+config then reinstall (implies --force) --detach background install/update/restore; returns pid+log at once LONG INSTALLS, DISCONNECTS & RETRY ---------------------------------- An install takes ~5-10 min (image pull). To survive an SSH drop, add --detach: ... bash <(curl -sL .../install.sh) --install --detach -y --json It backgrounds itself and returns immediately: {"status":"detached","action":"install","pid":N,"log":"./zfc-install.log","result_file":".zfc_install_result.json"} Then poll: cat .zfc_install_result.json (appears on completion) and/or tail -f ./zfc-install.log. (Even without --detach, agent runs always log to ZFC_LOG_FILE and ignore SIGHUP.) Retry after an interruption: - Half-finished install (ports busy -> exit 11/16): re-run --install --force (tears down old containers, frees ports, rebuilds the built-in DB). - Totally clean slate: --clean-install (implies --force; does NOT wipe an external DB). - It actually completed and you just want newer images: --update (keeps data). --force on a COMPLETE install is blocked (exit 16) — use --update or --clean-install. NOTE: --force is a REBUILD (it recreates the built-in DB; data is NOT kept). --update is the keep-data path. UPDATE FAILURES -> AUTO-FIX --------------------------- On a failed --update, run: ... --doctor --json It returns {"status":"ok|degraded|broken","services":[...], "schema":{"db_fingerprint","binary_fingerprint","db_status","delta_class","destructive_ops"}, "findings":[{"id","severity","detail","hint"}]}. Then: - schema.delta_class="additive" AND db_status="stable" (exit 18/19): set ZFC_ALLOW_SCHEMA_FINGERPRINT_MISMATCH=1 and restart the app containers, or re-run --update. - schema.delta_class="destructive" or "unknown": re-run --update (migrates + re-stamps). Do NOT set the override. - schema.db_status != "stable" (exit 18): restore latest schema_backup/db_backup_*.sql, then --update. - exit 20 (image pull): check DOCKER_REGISTRY / network / credentials, retry. - findings docker_old / compose_v1: upgrade Docker / install docker-compose-plugin, retry. The fingerprint override is safe ONLY for additive/index-only schema deltas (verify via --doctor first). USEFUL OPTIONAL ENV (defaults in parens) ---------------------------------------- CADDY_ENABLED(true) CADDY_EMAIL(optional) POSTGRES_TYPE(builtin) REDIS_TYPE(builtin) TDENGINE_TYPE(builtin|external|disabled) external DB needs EXTERNAL__HOST/PORT/USER/PASSWORD (TDengine WS/REST port = 6041) DOCKER_REGISTRY(hub.covm.net) IMAGE_TAG(latest) ZFC_AUTO_INSTALL_DOCKER(1) ZFC_VALIDATE_LICENSE(1) ZFC_SETUP_TIME_SYNC(1) ZFC_FORCE(0) ZFC_ASSUME_YES(1) ZFC_CLEAN_INSTALL(0) ZFC_DETACH(0) ZFC_LOG_FILE(./zfc-install.log) ZFC_ALLOW_SCHEMA_FINGERPRINT_MISMATCH(0) (additive deltas only; see UPDATE FAILURES) You may also write these to a file and pass --config FILE (env still wins over file). RULES ----- - Do not invent values. Ask the user for the 4 required values if missing. - Never print the admin token to any external/3rd-party service; show it only to the user. - If a step fails, read the JSON `reason` + exit code, fix the specific cause, and retry — do not blindly loop. Surface blocking problems (bad DNS, no root) to the user.