diff --git a/npm_install.py b/npm_install.py index 104b627..dd92ac9 100644 --- a/npm_install.py +++ b/npm_install.py @@ -333,23 +333,53 @@ def setup_angie(): WRAP = """#!/bin/sh # nginx compat -> angie; safe config test (-t) -# - remove all user-provided -g -# - force pid to /tmp during tests to avoid /run/angie perms -if printf ' %s ' "$@" | grep -q ' -t '; then - set -- "$@" - NEW_ARGS="" - while [ "$#" -gt 0 ]; do - if [ "$1" = "-g" ]; then - shift 2 +# - strip all user-provided -g flags +# - when running with -t, use a temp config without 'pid' and set pid via -g + +strip_pid_conf() { + # 1) find base config from -c if provided, otherwise default + local base_conf="/etc/angie/angie.conf" + local next_is_c= + local arg + for arg in "$@"; do + if [ -n "$next_is_c" ]; then + base_conf="$arg" + next_is_c= continue fi - NEW_ARGS="$NEW_ARGS \"${1}\"" - shift + [ "$arg" = "-c" ] && next_is_c=1 done + + # 2) create a temporary 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) + 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 and -c (we will pass our own -c) + NEW_ARGS="" + skip_next="" + for a in "$@"; do + if [ -n "$skip_next" ]; then + skip_next="" + continue + fi + if [ "$a" = "-g" ] || [ "$a" = "-c" ]; then + skip_next=1 + continue + fi + NEW_ARGS="$NEW_ARGS $a" + done + + TMP_CONF="$(strip_pid_conf "$@")" # shellcheck disable=SC2086 - eval set -- $NEW_ARGS - exec /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" "$@" + exec /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" -c "$TMP_CONF" $NEW_ARGS else + # full compatibility (e.g. -s reload): forward everything to angie exec /usr/sbin/angie "$@" fi """