feat(runtime): bound recovery and add safe release supervision

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-10 22:51:58 +03:00
1 parent 780ca71e17
commit b1e458a0a5
16 files changed
+941 -66

No files matched your search

+33 -1
View File
@@ -31,9 +31,40 @@ Then build and start only this Compose project. The rendered configuration
contains the environment password, so never use plain `docker compose config`
in logs or shared terminals.
By default Compose uses the locally built `zapret-autotune-managed-target:local`.
Tags are only local build/test candidates, not production release references.
For production promotion, set `ZAPRET_AUTOTUNE_IMAGE=<registry>/<managed-target>@sha256:<digest>`
in the private `.env` and pull that immutable image before starting the unit.
Use a managed target image, not the generic image; the systemd command never
builds images. Do not enable the production service with a tag or local default.
Offline static guard (from repository root):
`python3 deploy/managed-target/check_static.py`.
## Optional native systemd supervision
For unattended boot, place this checkout at `/opt/zapret2-autotune`, provision
`deploy/managed-target/.env` and state as above, and build the target image first.
For production, select and pull the immutable managed-target digest as above
instead of using a local build tag.
Install `deploy/managed-target/zapret-autotune.service` in `/etc/systemd/system/`,
then run `systemctl daemon-reload` and `systemctl enable --now zapret-autotune`.
Do not simultaneously start the same project with detached Compose.
Enabling the unit starts this isolated target on subsequent boots. `ExecStop`
only stops `target`; it does not replace the foreground process's failure code.
An explicit service stop suppresses restart, including during a shutdown race.
Compose has no automatic restart. The foreground systemd unit restarts **only
exit 75**, with at most three starts per six hours. Clean typed recovery timeouts,
unexpected monitor exits/crashes, and Shadowsocks failures qualify only if
shutdown cleanup succeeds. Configuration (64), safety/database/rollback/cleanup
failures (78), and graceful SIGTERM (0) never request restart. Investigate and
repair nonretry failures before manually starting again; do not clear state.
Monitor cancellation/join is bounded to 60 seconds, final target-local zapret
stop gets 30 seconds then forced kill after five more, and each Shadowsocks join
gets five seconds. Exceeding a join bound fails closed. Compose grants 120
seconds; systemd grants 180 seconds.
## Isolation and runtime contract
Only SOCKS TCP/UDP is published on host
@@ -47,9 +78,10 @@ password before starting child processes.
The dedicated bridge is not shared with existing services. No host networking,
Docker socket, existing mounts, host Lua/fakes or privileged mode; all
capabilities are dropped except `NET_ADMIN`, `NET_RAW`, `SETUID`, `SETGID`.
capabilities are dropped except `NET_ADMIN`, `NET_RAW`, `SETUID`, `SETGID`, `KILL`.
`NET_ADMIN` covers nft/NFQUEUE; `NET_RAW` covers nfqws2 raw sends. Zapret2's
`nfqws2 --user=tpws` needs `SETUID`/`SETGID` for UID/GID switching.
`KILL` allows bounded cleanup of workers that have dropped their UID.
Startup order: ss-server/ss-local → listener 1080 → guarded managed init on
fresh state (status on recreation) → target-local `zapret2 start` → supervised