feat: Update 5 and remove 1 files
This commit is contained in:
@@ -1,170 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script checks ALL services on the server and returns a status for each.
|
||||
|
||||
# Return format is simple ENV with the following format:
|
||||
# SERVICE_NAME_HEALTH=healthy|unhealthy|unknown
|
||||
# SERVICE_NAME_PORTS=port1,port2,port3
|
||||
|
||||
# Get all services on the server
|
||||
SCRIPT_DIR="$(dirname "$0")"
|
||||
|
||||
# export the passed variables from C++, so subshell can use them.
|
||||
export AGENT_PATH="${AGENT_PATH}"
|
||||
export HOST_NAME="${HOST_NAME}"
|
||||
export SERVER="${SERVER}"
|
||||
|
||||
# //------------------------------------------------------------------------------------------------
|
||||
# // remote paths
|
||||
# // DROPSHELL_DIR
|
||||
# // |-- backups
|
||||
# // |-- temp_files
|
||||
# // |-- agent
|
||||
# // | |-- bb64
|
||||
# // | |-- (other agent files, including _allservicesstatus.sh)
|
||||
# // |-- services
|
||||
# // |-- service name
|
||||
# // |-- config
|
||||
# // |-- service.env (actual service config)
|
||||
# // |-- .template_info.env
|
||||
# // |-- template
|
||||
# // |-- (script files)
|
||||
# // |-- config
|
||||
# // |-- service.env (default service config)
|
||||
# // |-- .template_info.env
|
||||
# // |-- (other config files for specific server&service)
|
||||
|
||||
# Get all services on the server
|
||||
SERVICES_PATH=$(realpath "${SCRIPT_DIR}/../services/")
|
||||
|
||||
CURRENT_OUTPUT=""
|
||||
CURRENT_EXIT_CODE=0
|
||||
|
||||
load_dotenv(){
|
||||
local file_path=$1
|
||||
if [ -f "${file_path}" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "${file_path}"
|
||||
fi
|
||||
}
|
||||
|
||||
_check_required_env_vars_allservicesstatus() {
|
||||
local required_vars=("$@")
|
||||
for var in "${required_vars[@]}"; do
|
||||
if [ -z "${!var}" ]; then
|
||||
_die "Required environment variable $var is not set"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function run_command() {
|
||||
local service_path=$1
|
||||
local command=$2
|
||||
local capture_output=${3:-false} # default to false if not specified
|
||||
|
||||
# check if the command is a file
|
||||
if [ ! -f "${service_path}/template/${command}.sh" ]; then
|
||||
return;
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
_check_required_env_vars_allservicesstatus "CONFIG_PATH" "SERVER" "SERVICE" "AGENT_PATH" "HOST_NAME" "TEMPLATE"
|
||||
|
||||
if [ "$capture_output" = "true" ]; then
|
||||
# Capture and return output
|
||||
bash "${service_path}/template/${command}.sh" 2>&1
|
||||
else
|
||||
# Run silently and return exit code
|
||||
bash "${service_path}/template/${command}.sh" > /dev/null 2>&1
|
||||
fi
|
||||
)
|
||||
CURRENT_EXIT_CODE=$?
|
||||
}
|
||||
|
||||
function command_exists() {
|
||||
local service_path=$1
|
||||
local command=$2
|
||||
if [ ! -f "${service_path}/template/${command}.sh" ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
if [ ! -d "${SERVICES_PATH}" ]; then
|
||||
echo "Services path does not exist: ${SERVICES_PATH}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get all service names
|
||||
SERVICE_NAMES=$(ls "${SERVICES_PATH}")
|
||||
|
||||
# Iterate over all service names
|
||||
for SERVICE_NAME in ${SERVICE_NAMES}; do
|
||||
|
||||
SERVICE_PATH=$(realpath "${SERVICES_PATH}/${SERVICE_NAME}")
|
||||
|
||||
#--------------------------------
|
||||
# Get the service health
|
||||
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
|
||||
|
||||
#--------------------------------
|
||||
# Get the service ports
|
||||
if ! command_exists "${SERVICE_PATH}" "ports"; then
|
||||
SERVICE_PORTS=""
|
||||
else
|
||||
run_command "${SERVICE_PATH}" "ports" "true"
|
||||
SERVICE_PORTS="${CURRENT_OUTPUT}"
|
||||
fi
|
||||
|
||||
#--------------------------------
|
||||
# return the health and ports
|
||||
echo "${SERVICE_NAME}_HEALTH=${SERVICE_HEALTH}"
|
||||
echo "${SERVICE_NAME}_PORTS=${SERVICE_PORTS}"
|
||||
done
|
@@ -73,7 +73,6 @@ install_bb64
|
||||
|
||||
required_files=(
|
||||
"$AGENT_PATH/bb64"
|
||||
"$AGENT_PATH/_allservicesstatus.sh"
|
||||
"$AGENT_PATH/common.sh"
|
||||
"$AGENT_PATH/datacommands.sh"
|
||||
)
|
||||
|
Reference in New Issue
Block a user