fix(guanghu-os): decouple release origin from tunnel retries
This commit is contained in:
parent
f3d204a724
commit
63a0780744
3 changed files with 34 additions and 12 deletions
|
|
@ -15,13 +15,13 @@ readonly FRONT_DOOR_HOST=43.139.217.141
|
|||
readonly FRONT_DOOR_USER=hololake-tunnel
|
||||
readonly FRONT_DOOR_PORT=19440
|
||||
|
||||
declare -a CHILDREN=()
|
||||
SERVER_PID=
|
||||
TUNNEL_PID=
|
||||
|
||||
cleanup() {
|
||||
trap - EXIT INT TERM
|
||||
for pid in "${CHILDREN[@]:-}"; do
|
||||
kill "$pid" 2>/dev/null || true
|
||||
done
|
||||
[[ -z ${TUNNEL_PID:-} ]] || kill "$TUNNEL_PID" 2>/dev/null || true
|
||||
[[ -z ${SERVER_PID:-} ]] || kill "$SERVER_PID" 2>/dev/null || true
|
||||
wait 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
|
@ -40,32 +40,37 @@ require_exact_runtime() {
|
|||
[[ $(stat -c '%a' "$TUNNEL_KEY") == 600 ]]
|
||||
}
|
||||
|
||||
start_pair() {
|
||||
CHILDREN=()
|
||||
start_server() {
|
||||
/usr/bin/setpriv --reuid=989 --regid=989 --init-groups --inh-caps=-all --reset-env \
|
||||
/usr/bin/env HOME=/nonexistent USER=hololake-release LOGNAME=hololake-release \
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
|
||||
HOLOLAKE_RELEASE_HOST=127.0.0.1 HOLOLAKE_RELEASE_PORT="$RELEASE_PORT" \
|
||||
HOLOLAKE_RELEASE_STATE_ROOT="$RELEASE_STATE_ROOT" \
|
||||
/usr/bin/node "$RELEASE_SERVER" &
|
||||
CHILDREN+=("$!")
|
||||
SERVER_PID=$!
|
||||
}
|
||||
|
||||
start_tunnel() {
|
||||
/usr/bin/ssh -N \
|
||||
-i "$TUNNEL_KEY" -o IdentitiesOnly=yes -o BatchMode=yes \
|
||||
-o UserKnownHostsFile="$TUNNEL_KNOWN_HOSTS" -o StrictHostKeyChecking=yes \
|
||||
-o ExitOnForwardFailure=yes -o ServerAliveInterval=20 -o ServerAliveCountMax=3 \
|
||||
-R "127.0.0.1:${FRONT_DOOR_PORT}:127.0.0.1:${RELEASE_PORT}" \
|
||||
"${FRONT_DOOR_USER}@${FRONT_DOOR_HOST}" &
|
||||
CHILDREN+=("$!")
|
||||
TUNNEL_PID=$!
|
||||
}
|
||||
|
||||
main() {
|
||||
require_exact_runtime
|
||||
start_server
|
||||
while :; do
|
||||
start_pair
|
||||
wait -n "${CHILDREN[@]}" || true
|
||||
for pid in "${CHILDREN[@]}"; do kill "$pid" 2>/dev/null || true; done
|
||||
wait 2>/dev/null || true
|
||||
kill -0 "$SERVER_PID" 2>/dev/null || return 1
|
||||
start_tunnel
|
||||
wait -n "$SERVER_PID" "$TUNNEL_PID" || true
|
||||
kill -0 "$SERVER_PID" 2>/dev/null || return 1
|
||||
kill "$TUNNEL_PID" 2>/dev/null || true
|
||||
wait "$TUNNEL_PID" 2>/dev/null || true
|
||||
TUNNEL_PID=
|
||||
sleep 2
|
||||
done
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
subject=${source_root}/scripts/hololake-release-bridge.sh
|
||||
|
||||
bash -n "$subject"
|
||||
grep -Fq 'start_server' "$subject"
|
||||
grep -Fq 'start_tunnel' "$subject"
|
||||
grep -Fq 'wait -n "$SERVER_PID" "$TUNNEL_PID"' "$subject"
|
||||
grep -Fq 'kill -0 "$SERVER_PID"' "$subject"
|
||||
if grep -Fq 'for pid in "${CHILDREN[@]}' "$subject"; then
|
||||
echo 'tunnel failure must not kill the healthy local release server' >&2
|
||||
exit 1
|
||||
fi
|
||||
echo HOLOLAKE_RELEASE_BRIDGE_LIFECYCLE_OK
|
||||
|
|
@ -96,6 +96,7 @@ run_gate pncc_runtime bash -c '
|
|||
node --test "$1/pncc-runtime/pncc-runtime.test.mjs"
|
||||
"$1/scripts/test-install-jd-pncc-runtime.sh"
|
||||
"$1/scripts/test-guanghu-master-init.sh"
|
||||
"$1/scripts/test-hololake-release-bridge.sh"
|
||||
' _ "${source_root}"
|
||||
run_gate linux_subcontrol_docker_backend \
|
||||
"${source_root}/scripts/test-linux-subcontrol-docker-backend.sh"
|
||||
|
|
|
|||
Loading…
Reference in a new issue