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 <noreply@anthropic.com>
This commit is contained in:
parent
02126aa7d3
commit
28acb7e70f
@ -44,46 +44,12 @@ get_status() {
|
|||||||
|
|
||||||
if is_running; then
|
if is_running; then
|
||||||
running="true"
|
running="true"
|
||||||
# Try to get container/process uptime
|
# Try to get process/container uptime
|
||||||
# LXC container
|
local pid=$(pgrep -f "local-ai" | head -1)
|
||||||
if command -v lxc-info >/dev/null 2>&1 && lxc-info -n localai -s 2>/dev/null | grep -q "RUNNING"; then
|
if [ -n "$pid" ] && [ -d "/proc/$pid" ]; then
|
||||||
# Get LXC container PID and calculate uptime
|
local start_time=$(stat -c %Y /proc/$pid 2>/dev/null || echo 0)
|
||||||
local lxc_pid=$(lxc-info -n localai -p 2>/dev/null | awk '{print $2}')
|
local now=$(date +%s)
|
||||||
if [ -n "$lxc_pid" ] && [ -d "/proc/$lxc_pid" ]; then
|
uptime=$((now - start_time))
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -245,7 +211,7 @@ get_health() {
|
|||||||
if is_running; then
|
if is_running; then
|
||||||
# Check API health endpoint
|
# Check API health endpoint
|
||||||
local response=$(wget -q -O - "http://127.0.0.1:$API_PORT/readyz" 2>/dev/null)
|
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"
|
healthy="true"
|
||||||
api_status="ok"
|
api_status="ok"
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user