From 0d953ea633f9b62fd8101366f7d1bf3bf1d0559c Mon Sep 17 00:00:00 2001 From: avivbintangaringga Date: Wed, 15 Jul 2026 11:13:41 +0700 Subject: [PATCH] fix(nix-monitor): track pid of the running remote check --- nix-monitor/nix_monitor_service.luau | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nix-monitor/nix_monitor_service.luau b/nix-monitor/nix_monitor_service.luau index a4fddcf..5db55f3 100644 --- a/nix-monitor/nix_monitor_service.luau +++ b/nix-monitor/nix_monitor_service.luau @@ -28,6 +28,7 @@ local checkDurationThreshold = cfg("check_duration_threshold") local systemStatsCheckInterval = cfg("system_stats_check_interval") local stateDir = "/tmp/nix-monitor" local remoteHashFile = stateDir .. "/remoteHash" +local remotePidFile = stateDir .. "/remoteHash.pid" local storeSizeFile = stateDir .. "/storeSize" local closureSizeFile = stateDir .. "/closureSize" local showUpdateNotification = true @@ -89,7 +90,7 @@ function checkRemoteHash(delay: number?) setState("lastRemoteCheckRunTime", os.time()) noctalia.writeFile(remoteHashFile, "") - noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} &`) + noctalia.runAsync(`sleep {delay} && {remoteHashCmd} > {remoteHashFile} & echo $! > {remotePidFile}`) end -- Check if the remoteHash check command is finished by reading the file @@ -114,7 +115,14 @@ end function cancelRemoteCheck() setState("isRemoteCheckRunning", false) - noctalia.runAsync(`kill $(ps -ef | grep "git ls-remote https://github.com/NixOS/nixpkgs" | grep -v grep | awk '\{print $2\}')`) + if noctalia.fileExists(remotePidFile) then + local pid = noctalia.string.trim(noctalia.readFile(remotePidFile)) + + if type(pid) == "string" and pid ~= "" then + noctalia.runAsync(`pkill -9 -P {pid}`) + end + noctalia.removeFile(remotePidFile) + end end -- Generation check