fix(bench): stop the service to zero before starting the next strategy
Some checks are pending
Check / Test & lint (push) Waiting to run

The init script's restart decides liveness with pgrep, so it can report
'already running' for a daemon that was started with the previous strategy's
config and leave it in place. The bench now stops, waits for the process
count to reach zero, and only then starts — both between strategies and in
the final restore, which is what puts the original config back in force.

Verified on the Keenetic: after a run the config on the router is
byte-identical to the original and exactly one nfqws2 process is running.
This commit is contained in:
Kirill Minovsky 2026-09-17 02:59:32 +03:00
parent e933a8edb4
commit 193da28295

View file

@ -87,10 +87,27 @@ IFACE=$(ip route show default 2>/dev/null |
[ -n "$IFACE" ] || IFACE=$(route -n 2>/dev/null | awk '$1 == "0.0.0.0" {print $8; exit}')
[ -n "$IFACE" ] || { echo "не удалось определить интерфейс провайдера" >&2; exit 1; }
# Перезапуск, который не полагается на `restart`: тот считает службу живой по
# pgrep и может не тронуть демон, поднятый с подменённым конфигом. Гасим до
# нуля процессов и только потом стартуем.
nfqws2_alive() {
[ "$(ps | grep -c '[n]fqws2')" -gt 0 ]
}
restart_service() {
"$SERVICE" stop >/dev/null 2>&1
i=0
while [ "$i" -lt 10 ] && nfqws2_alive; do
sleep 1
i=$((i + 1))
done
"$SERVICE" start >/dev/null 2>&1
}
restore() {
if [ -f "$BACKUP" ]; then
cp "$BACKUP" "$CONF"
"$SERVICE" restart >/dev/null 2>&1
restart_service
rm -f "$BACKUP" "$PATCHED" "$BENCH_PID"
if sh -n "$CONF" 2>/dev/null; then
echo "конфиг возвращён, служба перезапущена"
@ -182,7 +199,7 @@ for strategy in "$STRAT_DIR"/*.conf; do
continue
fi
cp "$PATCHED" "$CONF"
"$SERVICE" restart >/dev/null 2>&1
restart_service
ready=no
i=0