fix(localai): Add LXC container support to RPCD backend

- is_running() now checks LXC with lxc-info before Docker/Podman
- get_status() calculates uptime from LXC container PID
- Order: LXC -> Podman -> Docker -> native process

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-01-21 18:05:35 +01:00
parent e2b752984f
commit 4ac45bdb38
2 changed files with 23 additions and 8 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-localai
PKG_VERSION:=0.1.0
PKG_RELEASE:=14
PKG_RELEASE:=15
PKG_ARCH:=all
PKG_LICENSE:=Apache-2.0

View File

@ -18,16 +18,21 @@ load_config() {
config_get CONTEXT_SIZE main context_size "2048"
}
# Check if LocalAI is running (supports Docker/Podman container)
# Check if LocalAI is running (supports LXC, Docker, Podman)
is_running() {
# Check for container first (Docker/Podman)
# Check LXC container
if command -v lxc-info >/dev/null 2>&1; then
lxc-info -n localai -s 2>/dev/null | grep -q "RUNNING" && return 0
fi
# Check Podman container
if command -v podman >/dev/null 2>&1; then
podman ps --format '{{.Names}}' 2>/dev/null | grep -q "^localai$" && return 0
fi
# Check Docker container
if command -v docker >/dev/null 2>&1; then
docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^localai$" && return 0
fi
# Fallback to direct process check (LXC or native)
# Fallback to direct process check (native binary)
pgrep -f "local-ai" >/dev/null 2>&1
}
@ -39,11 +44,20 @@ get_status() {
if is_running; then
running="true"
# Try to get container uptime first
if command -v podman >/dev/null 2>&1; then
# 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
# Parse "Up X minutes/hours" format - just estimate
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)) ;;
@ -51,6 +65,7 @@ get_status() {
*) 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
@ -61,8 +76,8 @@ get_status() {
*) uptime=0 ;;
esac
fi
# Native process
else
# Fallback to process 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)