getting there
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
# This script checks ALL services on the server and returns a status for each.
|
||||
|
||||
@ -22,6 +21,16 @@ SCRIPT_DIR="$(dirname "$0")"
|
||||
# // |-- service.env
|
||||
# // |-- (other config files for specific server&service)
|
||||
|
||||
CURRENT_OUTPUT=""
|
||||
CURRENT_EXIT_CODE=0
|
||||
|
||||
load_dotenv(){
|
||||
local file_path=$1
|
||||
if [ -f "${file_path}" ]; then
|
||||
source <("${file_path}" | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
|
||||
fi
|
||||
}
|
||||
|
||||
function run_command() {
|
||||
local service_path=$1
|
||||
local command=$2
|
||||
@ -33,8 +42,11 @@ function run_command() {
|
||||
fi
|
||||
|
||||
# run the command in a subshell to prevent environment changes
|
||||
(
|
||||
source "${service_path}/config/service.env"
|
||||
CURRENT_OUTPUT=$(
|
||||
set -a
|
||||
load_dotenv "${service_path}/template/_default.env"
|
||||
load_dotenv "${service_path}/config/service.env"
|
||||
set +a
|
||||
|
||||
# update the main variables.
|
||||
export CONFIG_PATH="${service_path}/config"
|
||||
@ -43,16 +55,15 @@ function run_command() {
|
||||
|
||||
if [ "$capture_output" = "true" ]; then
|
||||
# Capture and return output
|
||||
CURRENT_OUTPUT=$(bash "${service_path}/template/${command}.sh" 2>&1)
|
||||
CURRENT_EXIT_CODE=$?
|
||||
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
|
||||
CURRENT_OUTPUT=""
|
||||
CURRENT_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
|
||||
@ -63,7 +74,7 @@ function command_exists() {
|
||||
}
|
||||
|
||||
# Get all services on the server
|
||||
SERVICES_PATH="${SCRIPT_DIR}/../../"
|
||||
SERVICES_PATH=$(realpath "${SCRIPT_DIR}/../../")
|
||||
|
||||
# Get all service names
|
||||
SERVICE_NAMES=$(ls "${SERVICES_PATH}")
|
||||
@ -71,7 +82,7 @@ SERVICE_NAMES=$(ls "${SERVICES_PATH}")
|
||||
# Iterate over all service names
|
||||
for SERVICE_NAME in ${SERVICE_NAMES}; do
|
||||
|
||||
SERVICE_PATH="${SERVICES_PATH}/${SERVICE_NAME}"
|
||||
SERVICE_PATH=$(realpath "${SERVICES_PATH}/${SERVICE_NAME}")
|
||||
|
||||
#--------------------------------
|
||||
# Get the service health
|
||||
|
Reference in New Issue
Block a user