feat(runtime): bound recovery and add safe release supervision
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
780ca71e17
commit
b1e458a0a5
16 files changed
+941
-66
No files matched your search
@@ -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
|
||||
|
||||
@@ -7,10 +7,12 @@ directory = Path(__file__).resolve().parent
|
||||
compose = (directory / "compose.yaml").read_text()
|
||||
entrypoint = (directory.parents[1] / "managed-target-entrypoint.sh").read_text()
|
||||
readme = (directory / "README.md").read_text()
|
||||
unit = (directory / "zapret-autotune.service").read_text()
|
||||
|
||||
# ponytail: checks the committed Compose shape, not arbitrary YAML; use a YAML
|
||||
# parser if this definition grows beyond its single target service.
|
||||
assert " privileged: false\n" in compose
|
||||
assert " image: ${ZAPRET_AUTOTUNE_IMAGE:-zapret-autotune-managed-target:local}\n" in compose
|
||||
assert " cap_drop: [ALL]\n" in compose
|
||||
assert " cap_add: [NET_ADMIN, NET_RAW, SETUID, SETGID, KILL]\n" in compose
|
||||
assert compose.count(" - type: bind\n") == 1
|
||||
@@ -26,3 +28,18 @@ assert "export SS_PASSWORD" not in entrypoint
|
||||
assert "Docker administrators/root can still read container" in readme
|
||||
assert "removed\nfrom the entrypoint environment" in readme
|
||||
assert "No host networking" in readme
|
||||
assert ' restart: "no"\n' in compose
|
||||
assert " stop_grace_period: 120s\n" in compose
|
||||
directives = dict(line.split("=", 1) for line in unit.splitlines() if "=" in line)
|
||||
assert directives["Restart"] == "no"
|
||||
assert directives["RestartForceExitStatus"] == "75"
|
||||
assert "RestartPreventExitStatus" not in directives
|
||||
assert directives["StartLimitIntervalSec"] == "6h"
|
||||
assert directives["StartLimitBurst"] == "3"
|
||||
assert directives["TimeoutStopSec"] == "180s"
|
||||
assert directives["WorkingDirectory"] == "/opt/zapret2-autotune"
|
||||
assert directives["WantedBy"] == "multi-user.target"
|
||||
compose_command = "/usr/bin/docker compose --env-file deploy/managed-target/.env -f deploy/managed-target/compose.yaml"
|
||||
assert directives["ExecStart"] == compose_command + " up --no-build --abort-on-container-exit --exit-code-from target target"
|
||||
assert directives["ExecStop"] == compose_command + " stop target"
|
||||
assert "timeout -k 5 30 /opt/zapret2/init.d/sysv/zapret2 stop" in entrypoint
|
||||
@@ -1,7 +1,7 @@
|
||||
name: zapret-autotune-managed-test
|
||||
services:
|
||||
target:
|
||||
image: zapret-autotune-managed-target:local
|
||||
image: ${ZAPRET_AUTOTUNE_IMAGE:-zapret-autotune-managed-target:local}
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: Dockerfile.target
|
||||
@@ -30,7 +30,8 @@ services:
|
||||
tmpfs:
|
||||
- /run/zapret-autotune-ss:rw,noexec,nosuid,nodev,size=1m,mode=0700,uid=0,gid=0
|
||||
networks: [target]
|
||||
stop_grace_period: 45s
|
||||
restart: "no"
|
||||
stop_grace_period: 120s
|
||||
networks:
|
||||
target:
|
||||
driver: bridge
|
||||
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=Isolated zapret-autotune managed target
|
||||
Requires=docker.service
|
||||
After=docker.service
|
||||
StartLimitIntervalSec=6h
|
||||
StartLimitBurst=3
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/opt/zapret2-autotune
|
||||
ExecStart=/usr/bin/docker compose --env-file deploy/managed-target/.env -f deploy/managed-target/compose.yaml up --no-build --abort-on-container-exit --exit-code-from target target
|
||||
ExecStop=/usr/bin/docker compose --env-file deploy/managed-target/.env -f deploy/managed-target/compose.yaml stop target
|
||||
Restart=no
|
||||
RestartForceExitStatus=75
|
||||
RestartSec=30s
|
||||
TimeoutStopSec=180s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in new issue
Block a user