From ccdf1187903228b981d68d4219fe340ebe0c1d97 Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Sat, 14 Dec 2024 09:01:05 +0100 Subject: [PATCH 1/2] Cleanly stop a service group if a service exits --- modules/services.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/services.nix b/modules/services.nix index fb4e264..c36234d 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -77,7 +77,7 @@ let rm "$PRJ_DATA_DIR/pids/${gName}.pid" wait $pid } - trap "on_stop" SIGINT SIGTERM SIGHUP + trap "on_stop" SIGINT SIGTERM SIGHUP EXIT wait $pid '').outPath; } From 81e38d476d871120dc53d3647ede8623d05b96cf Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Sat, 14 Dec 2024 09:23:28 +0100 Subject: [PATCH 2/2] Don't try to kill a process that already exited --- modules/services.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/services.nix b/modules/services.nix index c36234d..b630bae 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -73,7 +73,9 @@ let pid=$! echo $pid > "$PRJ_DATA_DIR/pids/${gName}.pid" on_stop() { - kill -TERM $pid + if ps -p $pid > /dev/null; then + kill -TERM $pid + fi rm "$PRJ_DATA_DIR/pids/${gName}.pid" wait $pid }