fix wrapper
This commit is contained in:
@@ -332,12 +332,13 @@ def setup_angie():
|
||||
write_file(Path("/usr/sbin/nginx"), "#!/bin/sh\nexec /usr/sbin/angie \"$@\"\n", 0o755)
|
||||
|
||||
WRAP = """#!/bin/sh
|
||||
# nginx compat -> angie; safe config test (-t)
|
||||
# - strip all user-provided -g flags
|
||||
# - when running with -t, use a temp config without 'pid' and set pid via -g
|
||||
# nginx compat -> angie; silent safe config test (-t)
|
||||
# - drop all user -g
|
||||
# - for -t use temp config without 'pid'
|
||||
# - suppress ALL output; return angie's exit code
|
||||
|
||||
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 next_is_c=
|
||||
local arg
|
||||
@@ -350,17 +351,17 @@ strip_pid_conf() {
|
||||
[ "$arg" = "-c" ] && next_is_c=1
|
||||
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
|
||||
tmpd="$(mktemp -d)"
|
||||
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"
|
||||
printf '%s\n' "$tmpc"
|
||||
}
|
||||
|
||||
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=""
|
||||
skip_next=""
|
||||
for a in "$@"; do
|
||||
@@ -376,12 +377,16 @@ if printf ' %s ' "$@" | grep -q ' -t '; then
|
||||
done
|
||||
|
||||
TMP_CONF="$(strip_pid_conf "$@")"
|
||||
# run test SILENTLY; propagate exit code; cleanup temp
|
||||
# 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
|
||||
# full compatibility (e.g. -s reload): forward everything to angie
|
||||
exec /usr/sbin/angie "$@"
|
||||
fi
|
||||
|
||||
"""
|
||||
write_file(Path("/usr/sbin/nginx"), WRAP, 0o755)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user