From 28acb7e70f44457643fd3da054c90587e52d29e6 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Tue, 3 Feb 2026 19:04:23 +0100 Subject: [PATCH] fix(localai): Fix health check and uptime detection in RPCD handler Health check grep was case-sensitive ("ok") but LocalAI returns "OK". Uptime detection fell into the lxc-info branch (command exists on router) even though no localai container runs, causing uptime to always be 0. Simplified to always use /proc/PID which works for both native and containerized processes. Co-Authored-By: Claude Opus 4.5 --- .../root/usr/libexec/rpcd/luci.localai | 48 +++---------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/package/secubox/luci-app-localai/root/usr/libexec/rpcd/luci.localai b/package/secubox/luci-app-localai/root/usr/libexec/rpcd/luci.localai index 6cbb461e..80905635 100755 --- a/package/secubox/luci-app-localai/root/usr/libexec/rpcd/luci.localai +++ b/package/secubox/luci-app-localai/root/usr/libexec/rpcd/luci.localai @@ -44,46 +44,12 @@ get_status() { if is_running; then running="true" - # Try to get container/process uptime - # LXC container - if command -v lxc-info >/dev/null 2>&1 && lxc-info -n localai -s 2>/dev/null | grep -q "RUNNING"; then - # Get LXC container PID and calculate uptime - local lxc_pid=$(lxc-info -n localai -p 2>/dev/null | awk '{print $2}') - if [ -n "$lxc_pid" ] && [ -d "/proc/$lxc_pid" ]; then - local start_time=$(stat -c %Y /proc/$lxc_pid 2>/dev/null || echo 0) - local now=$(date +%s) - uptime=$((now - start_time)) - fi - # Podman container - elif command -v podman >/dev/null 2>&1; then - local status=$(podman ps --filter "name=localai" --format '{{.Status}}' 2>/dev/null | head -1) - if [ -n "$status" ]; then - case "$status" in - *minute*) uptime=$(($(echo "$status" | grep -oE '[0-9]+' | head -1) * 60)) ;; - *hour*) uptime=$(($(echo "$status" | grep -oE '[0-9]+' | head -1) * 3600)) ;; - *second*) uptime=$(echo "$status" | grep -oE '[0-9]+' | head -1) ;; - *) uptime=0 ;; - esac - fi - # Docker container - elif command -v docker >/dev/null 2>&1; then - local status=$(docker ps --filter "name=localai" --format '{{.Status}}' 2>/dev/null | head -1) - if [ -n "$status" ]; then - case "$status" in - *minute*) uptime=$(($(echo "$status" | grep -oE '[0-9]+' | head -1) * 60)) ;; - *hour*) uptime=$(($(echo "$status" | grep -oE '[0-9]+' | head -1) * 3600)) ;; - *second*) uptime=$(echo "$status" | grep -oE '[0-9]+' | head -1) ;; - *) uptime=0 ;; - esac - fi - # Native process - else - local pid=$(pgrep -f "local-ai" | head -1) - if [ -n "$pid" ] && [ -d "/proc/$pid" ]; then - local start_time=$(stat -c %Y /proc/$pid 2>/dev/null || echo 0) - local now=$(date +%s) - uptime=$((now - start_time)) - fi + # Try to get process/container uptime + local pid=$(pgrep -f "local-ai" | head -1) + if [ -n "$pid" ] && [ -d "/proc/$pid" ]; then + local start_time=$(stat -c %Y /proc/$pid 2>/dev/null || echo 0) + local now=$(date +%s) + uptime=$((now - start_time)) fi fi @@ -245,7 +211,7 @@ get_health() { if is_running; then # Check API health endpoint local response=$(wget -q -O - "http://127.0.0.1:$API_PORT/readyz" 2>/dev/null) - if echo "$response" | grep -q "ok"; then + if echo "$response" | grep -qi "ok"; then healthy="true" api_status="ok" else