mirror of
https://gitcode.com/GitHub_Trending/az/azerothcore-wotlk.git
synced 2026-07-10 19:03:11 +00:00
fix(startup): harden startup guard parsing
This commit is contained in:
@@ -53,8 +53,13 @@ function config_value() {
|
||||
fi
|
||||
|
||||
awk -F= -v key="$key" '
|
||||
$0 ~ "^[[:space:]]*" key "[[:space:]]*=" {
|
||||
value = $2
|
||||
{
|
||||
configKey = $1
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", configKey)
|
||||
}
|
||||
configKey == key {
|
||||
value = $0
|
||||
sub(/^[^=]*=/, "", value)
|
||||
sub(/[[:space:]]*[#;].*$/, "", value)
|
||||
gsub(/"/, "", value)
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
|
||||
@@ -145,12 +150,32 @@ function wait_for_startup_guard() {
|
||||
local interval="${AC_STARTUP_GUARD_INTERVAL:-2}"
|
||||
local elapsed=0
|
||||
local instances ports
|
||||
local sleep_for
|
||||
local warned=0
|
||||
|
||||
if [ "${AC_STARTUP_SKIP_GUARD:-0}" = "1" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "$timeout" in
|
||||
''|*[!0-9]*)
|
||||
echo "Startup guard: invalid AC_STARTUP_GUARD_TIMEOUT '$timeout', using 90."
|
||||
timeout=90
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$interval" in
|
||||
''|*[!0-9]*)
|
||||
echo "Startup guard: invalid AC_STARTUP_GUARD_INTERVAL '$interval', using 2."
|
||||
interval=2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$interval" -lt 1 ]; then
|
||||
echo "Startup guard: AC_STARTUP_GUARD_INTERVAL must be at least 1, using 1."
|
||||
interval=1
|
||||
fi
|
||||
|
||||
while true; do
|
||||
instances="$(find_existing_instances)"
|
||||
ports="$(find_listening_guard_ports)"
|
||||
@@ -176,8 +201,15 @@ function wait_for_startup_guard() {
|
||||
warned=1
|
||||
fi
|
||||
|
||||
sleep "$interval"
|
||||
elapsed=$((elapsed + interval))
|
||||
sleep_for="$interval"
|
||||
if [ $((elapsed + sleep_for)) -gt "$timeout" ]; then
|
||||
sleep_for=$((timeout - elapsed))
|
||||
fi
|
||||
|
||||
[ "$sleep_for" -le 0 ] && continue
|
||||
|
||||
sleep "$sleep_for"
|
||||
elapsed=$((elapsed + sleep_for))
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ EOF
|
||||
"$TEST_DIR/bin/duplicate-server" -c "$TEST_DIR/test-server.conf" &
|
||||
local duplicate_pid=$!
|
||||
|
||||
AC_STARTUP_GUARD_TIMEOUT=1 AC_STARTUP_GUARD_INTERVAL=1 run "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "duplicate-server" "" "$TEST_DIR/test-server.conf" "" "" 0
|
||||
AC_STARTUP_GUARD_TIMEOUT=1 AC_STARTUP_GUARD_INTERVAL=1 run timeout 5s "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "duplicate-server" "" "$TEST_DIR/test-server.conf" "" "" 0
|
||||
kill "$duplicate_pid" 2>/dev/null || true
|
||||
wait "$duplicate_pid" 2>/dev/null || true
|
||||
|
||||
@@ -89,7 +89,7 @@ EOF
|
||||
nc -l 127.0.0.1 "$listen_port" >/dev/null &
|
||||
local listener_pid=$!
|
||||
|
||||
AC_STARTUP_GUARD_TIMEOUT=1 AC_STARTUP_GUARD_INTERVAL=1 run "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "worldserver" "" "$TEST_DIR/worldserver.conf" "" "" 0
|
||||
AC_STARTUP_GUARD_TIMEOUT=1 AC_STARTUP_GUARD_INTERVAL=1 run timeout 5s "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "worldserver" "" "$TEST_DIR/worldserver.conf" "" "" 0
|
||||
kill "$listener_pid" 2>/dev/null || true
|
||||
wait "$listener_pid" 2>/dev/null || true
|
||||
|
||||
@@ -99,6 +99,37 @@ EOF
|
||||
[[ "$output" =~ "configured port(s) still listening: $listen_port" ]]
|
||||
}
|
||||
|
||||
@test "starter: should parse config keys literally for startup guard" {
|
||||
if ! command -v nc >/dev/null 2>&1; then
|
||||
skip "nc is required for this test"
|
||||
fi
|
||||
|
||||
cat > "$TEST_DIR/bin/worldserver" << 'EOF'
|
||||
#!/usr/bin/env bash
|
||||
echo "worldserver started"
|
||||
EOF
|
||||
chmod +x "$TEST_DIR/bin/worldserver"
|
||||
|
||||
local listen_port=40124
|
||||
cat > "$TEST_DIR/worldserver.conf" << EOF
|
||||
WorldServerPort = 40125
|
||||
SOAPXEnabled = 1
|
||||
SOAPXPort = $listen_port
|
||||
SOAP.Enabled = 0
|
||||
EOF
|
||||
nc -l 127.0.0.1 "$listen_port" >/dev/null &
|
||||
local listener_pid=$!
|
||||
|
||||
AC_STARTUP_GUARD_TIMEOUT=1 AC_STARTUP_GUARD_INTERVAL=1 run timeout 5s "$SCRIPT_DIR/starter" "$TEST_DIR/bin" "worldserver" "" "$TEST_DIR/worldserver.conf" "" "" 0
|
||||
kill "$listener_pid" 2>/dev/null || true
|
||||
wait "$listener_pid" 2>/dev/null || true
|
||||
|
||||
debug_on_failure
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "worldserver started" ]]
|
||||
[[ ! "$output" =~ "Startup guard: refusing" ]]
|
||||
}
|
||||
|
||||
# ===== SIMPLE RESTARTER TESTS =====
|
||||
|
||||
@test "simple-restarter: should fail with missing parameters" {
|
||||
|
||||
Reference in New Issue
Block a user