From 04d240bbd2aa2ab89c7443686eab4bf00b80d831 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 29 Aug 2025 18:28:07 +1200 Subject: [PATCH] Update source/agent-remote/_allservicesstatus.sh --- source/agent-remote/_allservicesstatus.sh | 36 +++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/source/agent-remote/_allservicesstatus.sh b/source/agent-remote/_allservicesstatus.sh index fa53e40..dad2b3d 100755 --- a/source/agent-remote/_allservicesstatus.sh +++ b/source/agent-remote/_allservicesstatus.sh @@ -68,16 +68,30 @@ function run_command() { fi # run the command in a subshell to prevent environment changes + # This subshell creates a completely isolated environment for each service CURRENT_OUTPUT=$( + # Start with a clean environment for each service set -a - load_dotenv "${service_path}/config/service.env" - load_dotenv "${service_path}/config/.template_info.env" - - # update the main variables. - export CONFIG_PATH="${service_path}/config" - export SERVICE="${SERVICE_NAME}" + # First set the core variables that other env vars might reference + export SERVER="${SERVER}" + export SERVICE_NAME="" # Will be set from .template_info.env + export SERVICE="" # Will be set after loading SERVICE_NAME export DOCKER_CLI_HINTS=false + export AGENT_PATH="${AGENT_PATH}" + export HOST_NAME="${HOST_NAME}" + + # Load the template info first to get SERVICE_NAME and TEMPLATE + load_dotenv "${service_path}/config/.template_info.env" + + # Now set SERVICE from SERVICE_NAME (critical for CONTAINER_NAME expansion) + export SERVICE="${SERVICE_NAME}" + + # Set CONFIG_PATH before loading service.env as it might be referenced + export CONFIG_PATH="${service_path}/config" + + # Now load service.env which can properly expand variables like CONTAINER_NAME=${SERVICE} + load_dotenv "${service_path}/config/service.env" set +a @@ -122,11 +136,21 @@ for SERVICE_NAME in ${SERVICE_NAMES}; do if ! command_exists "${SERVICE_PATH}" "status"; then SERVICE_HEALTH="unknown" else + # Debug: capture output to see what's failing + run_command "${SERVICE_PATH}" "status" "true" + ERROR_OUTPUT="${CURRENT_OUTPUT}" run_command "${SERVICE_PATH}" "status" "false" if [ "${CURRENT_EXIT_CODE}" -eq 0 ]; then SERVICE_HEALTH="healthy" else SERVICE_HEALTH="unhealthy" + # Debug: show error for simple-object-server services + if [ -f "${SERVICE_PATH}/config/.template_info.env" ]; then + source "${SERVICE_PATH}/config/.template_info.env" + if [ "${TEMPLATE}" = "simple-object-server" ]; then + >&2 echo "DEBUG ${SERVICE_NAME}: ${ERROR_OUTPUT}" + fi + fi fi fi