feat(deploy): define isolated managed test target
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
0b4b909a20
commit
c5cabf076f
9 files changed
+159
-10
No files matched your search
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
umask 077
|
||||
unset SS_PASSWORD ss_password
|
||||
[ "$#" -eq 0 ] || { echo 'error: target entrypoint accepts no arguments' >&2; exit 1; }
|
||||
|
||||
# Credentials never enter exported variables or Shadowsocks command arguments.
|
||||
ss_password=$(cat /run/secrets/ss_password) || exit 1
|
||||
case "$ss_password" in
|
||||
''|*[!0123456789abcdefABCDEF]*)
|
||||
echo 'error: target secret must contain only hexadecimal characters' >&2; exit 1 ;;
|
||||
esac
|
||||
[ "${#ss_password}" -ge 32 ] || { echo 'error: target secret must be at least 32 hex characters' >&2; exit 1; }
|
||||
config_dir=/run/zapret-autotune-ss
|
||||
awk '$2 == "/run/zapret-autotune-ss" && $3 == "tmpfs" { found=1 } END { exit !found }' /proc/mounts || {
|
||||
echo 'error: target Shadowsocks config directory must be a dedicated tmpfs' >&2; exit 1;
|
||||
}
|
||||
chmod 0700 "$config_dir"
|
||||
cat > "$config_dir/server.json" <<EOF
|
||||
{"server":"0.0.0.0","server_port":8388,"password":"$ss_password","method":"chacha20-ietf-poly1305","mode":"tcp_and_udp"}
|
||||
EOF
|
||||
cat > "$config_dir/local.json" <<EOF
|
||||
{"server":"127.0.0.1","server_port":8388,"local_address":"0.0.0.0","local_port":1080,"password":"$ss_password","method":"chacha20-ietf-poly1305","mode":"tcp_and_udp"}
|
||||
EOF
|
||||
chmod 0600 "$config_dir/server.json" "$config_dir/local.json"
|
||||
unset ss_password
|
||||
|
||||
server_pid=
|
||||
local_pid=
|
||||
zapret_started=0
|
||||
cleanup() {
|
||||
trap - EXIT INT TERM
|
||||
# Dedicated PID/network namespace: no host/other-target stop.
|
||||
if [ "$zapret_started" -eq 1 ]; then
|
||||
/opt/zapret2/init.d/sysv/zapret2 stop || true
|
||||
fi
|
||||
for pid in "$local_pid" "$server_pid"; do
|
||||
[ -z "$pid" ] || kill "$pid" 2>/dev/null || true
|
||||
done
|
||||
for pid in "$local_pid" "$server_pid"; do
|
||||
[ -z "$pid" ] || wait "$pid" 2>/dev/null || true
|
||||
done
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap 'exit 0' INT TERM
|
||||
|
||||
# Never invoke /opt/entrypoint.sh: zapret must start AFTER managed init.
|
||||
ss-server -c "$config_dir/server.json" &
|
||||
server_pid=$!
|
||||
ss-local -c "$config_dir/local.json" &
|
||||
local_pid=$!
|
||||
|
||||
# Bounded readiness, no network probe. Init/status verifies socket ownership.
|
||||
attempt=0
|
||||
until awk '$2 == "00000000:0438" && $4 == "0A" { found=1 } END { exit !found }' /proc/net/tcp; do
|
||||
kill -0 "$server_pid" && kill -0 "$local_pid"
|
||||
attempt=$((attempt + 1))
|
||||
[ "$attempt" -lt 30 ] || { echo 'error: target SOCKS listener timeout' >&2; exit 1; }
|
||||
sleep 1
|
||||
done
|
||||
if [ ! -e "$ZAPRET_CONFIG" ]; then
|
||||
zapret-autotune managed init
|
||||
else
|
||||
# Never reinitialize/adopt persisted state; drift/pending state fails closed.
|
||||
zapret-autotune managed status
|
||||
fi
|
||||
zapret_started=1
|
||||
/opt/zapret2/init.d/sysv/zapret2 start
|
||||
|
||||
# Process supervision only; no managed monitor/recovery command exists yet.
|
||||
while kill -0 "$server_pid" && kill -0 "$local_pid"; do
|
||||
sleep 1
|
||||
done
|
||||
echo 'error: target Shadowsocks process exited' >&2
|
||||
exit 1
|
||||
Reference in new issue
Block a user