fix wrapper

This commit is contained in:
Mateusz Gruszczyński
2025-10-23 22:48:37 +02:00
parent 90262e9dc4
commit 20d2fab709

View File

@@ -332,12 +332,13 @@ def setup_angie():
write_file(Path("/usr/sbin/nginx"), "#!/bin/sh\nexec /usr/sbin/angie \"$@\"\n", 0o755) write_file(Path("/usr/sbin/nginx"), "#!/bin/sh\nexec /usr/sbin/angie \"$@\"\n", 0o755)
WRAP = """#!/bin/sh WRAP = """#!/bin/sh
# nginx compat -> angie; safe config test (-t) # nginx compat -> angie; silent safe config test (-t)
# - strip all user-provided -g flags # - drop all user -g
# - when running with -t, use a temp config without 'pid' and set pid via -g # - for -t use temp config without 'pid'
# - suppress ALL output; return angie's exit code
strip_pid_conf() { strip_pid_conf() {
# 1) find base config from -c if provided, otherwise default # find base config from -c if provided, else default
local base_conf="/etc/angie/angie.conf" local base_conf="/etc/angie/angie.conf"
local next_is_c= local next_is_c=
local arg local arg
@@ -350,17 +351,17 @@ strip_pid_conf() {
[ "$arg" = "-c" ] && next_is_c=1 [ "$arg" = "-c" ] && next_is_c=1
done done
# 2) create a temporary config with any top-level 'pid ...;' removed # create a temp config with any top-level 'pid ...;' removed
local tmpd tmpc local tmpd tmpc
tmpd="$(mktemp -d)" tmpd="$(mktemp -d)"
tmpc="$tmpd/angie.conf" tmpc="$tmpd/angie.conf"
# remove lines starting with 'pid ...;' (with optional leading whitespace) # remove 'pid ...;' at start of line (optionally indented)
sed -E 's/^[[:space:]]*pid[[:space:]]+[^;]+;//' "$base_conf" > "$tmpc" sed -E 's/^[[:space:]]*pid[[:space:]]+[^;]+;//' "$base_conf" > "$tmpc"
printf '%s\n' "$tmpc" printf '%s\n' "$tmpc"
} }
if printf ' %s ' "$@" | grep -q ' -t '; then if printf ' %s ' "$@" | grep -q ' -t '; then
# rebuild args: drop every -g <arg> and -c <file> (we will pass our own -c) # rebuild args without any '-g <arg>' and without '-c <file>'
NEW_ARGS="" NEW_ARGS=""
skip_next="" skip_next=""
for a in "$@"; do for a in "$@"; do
@@ -376,12 +377,16 @@ if printf ' %s ' "$@" | grep -q ' -t '; then
done done
TMP_CONF="$(strip_pid_conf "$@")" TMP_CONF="$(strip_pid_conf "$@")"
# run test SILENTLY; propagate exit code; cleanup temp
# shellcheck disable=SC2086 # shellcheck disable=SC2086
exec /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" -c "$TMP_CONF" $NEW_ARGS /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" -c "$TMP_CONF" $NEW_ARGS >/dev/null 2>&1
rc=$?
rm -rf "$(dirname "$TMP_CONF")"
exit $rc
else else
# full compatibility (e.g. -s reload): forward everything to angie
exec /usr/sbin/angie "$@" exec /usr/sbin/angie "$@"
fi fi
""" """
write_file(Path("/usr/sbin/nginx"), WRAP, 0o755) write_file(Path("/usr/sbin/nginx"), WRAP, 0o755)