From 2797550b7ebd192dd5fd745282f2d58a7467164c Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 4 Mar 2026 10:43:50 -0500 Subject: [PATCH] fix: implement cleanup function for LocalAGI service recovery during updates --- ct/localagi.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ct/localagi.sh b/ct/localagi.sh index e12961e37..aea5a2c85 100644 --- a/ct/localagi.sh +++ b/ct/localagi.sh @@ -21,7 +21,23 @@ variables color catch_errors +LOCALAGI_WAS_STOPPED=0 + +function cleanup_localagi_service() { + if [[ "${LOCALAGI_WAS_STOPPED:-0}" == "1" ]] && ! systemctl is-active -q localagi; then + msg_warn "LocalAGI service was stopped during update; attempting recovery start" + if systemctl start localagi; then + msg_ok "Recovered LocalAGI service" + else + msg_error "Failed to recover LocalAGI service" + fi + fi +} + function update_script() { + LOCALAGI_WAS_STOPPED=0 + trap cleanup_localagi_service EXIT + header_info check_container_storage check_container_resources @@ -34,6 +50,7 @@ function update_script() { if check_for_gh_release "localagi" "mudler/LocalAGI"; then msg_info "Stopping LocalAGI Service" systemctl stop localagi + LOCALAGI_WAS_STOPPED=1 msg_ok "Stopped LocalAGI Service" msg_info "Backing up Environment" @@ -93,6 +110,7 @@ function update_script() { msg_error "Failed to start LocalAGI service" exit 1 } + LOCALAGI_WAS_STOPPED=0 msg_ok "Started LocalAGI (external-llm)" msg_ok "Updated successfully!"