From c948ca7367e07076adff478319d5f9c8db17740a Mon Sep 17 00:00:00 2001 From: avi Date: Tue, 22 Sep 2026 12:24:26 -0500 Subject: [PATCH] =?UTF-8?q?update-app.sh:=20kill=20by=20pattern=20EXCLUDIN?= =?UTF-8?q?G=20own=20process=20lineage=20=E2=80=94=20pkill=20-f=20matched?= =?UTF-8?q?=20any=20ancestor=20shell=20mentioning=20the=20script=20path,?= =?UTF-8?q?=20so=20an=20update=20run=20could=20SIGTERM=20its=20own=20invok?= =?UTF-8?q?er;=20app-kill=20now=20walks=20the=20ppid=20chain=20and=20spare?= =?UTF-8?q?s=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/update-app.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/update-app.sh b/scripts/update-app.sh index d40779c..06e0c1a 100755 --- a/scripts/update-app.sh +++ b/scripts/update-app.sh @@ -28,13 +28,24 @@ if ! ./gradlew :app:createDistributable -q; then fi # Stop the app (and its engine) only AFTER a good build exists. +# NEVER match our own lineage: pkill -f also matches any ancestor shell +# whose command line merely mentions this script's path. +_selfpids() { local p=$$; while [ "$p" -gt 1 ]; do echo "$p"; p=$(ps -o ppid= -p "$p" 2>/dev/null | tr -d ' '); [ -z "$p" ] && break; done; } +_killpat() { + local pat="$1" pid + for pid in $(pgrep -f "$pat" 2>/dev/null); do + case " $(_selfpids) " in *" $pid "*) continue;; esac + # also skip the pgrep call itself via its subshell parent already covered + kill "$pid" 2>/dev/null + done +} # Packaged runs appear as .../bin/shonar-desktop; dev runs as java MainKt. -pkill -f 'com.shonar.desktop.MainKt' 2>/dev/null -pkill -f 'shonar-desktop/bin/shonar-desktop' 2>/dev/null -pkill -f 'uvicorn shonar.main:app' 2>/dev/null +_killpat 'com.shonar.desktop.MainKt' +_killpat 'shonar-desktop/bin/shonar-desktop' +_killpat 'uvicorn shonar.main:app' sleep 2 # Last resort: anything still holding a SHONAR window. -pkill -f 'shonar-desktop' 2>/dev/null +_killpat 'shonar-desktop' sleep 2 bin="$repo/app/build/compose/binaries/main/app/shonar-desktop/bin/shonar-desktop"