Aligning the different parts with the new directory and file structure.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
parent
67da992326
commit
399fe1d549
@ -9,6 +9,7 @@
|
|||||||
# Get all services on the server
|
# Get all services on the server
|
||||||
SCRIPT_DIR="$(dirname "$0")"
|
SCRIPT_DIR="$(dirname "$0")"
|
||||||
|
|
||||||
|
# //------------------------------------------------------------------------------------------------
|
||||||
# // remote paths
|
# // remote paths
|
||||||
# // DROPSHELL_DIR
|
# // DROPSHELL_DIR
|
||||||
# // |-- backups
|
# // |-- backups
|
||||||
@ -19,17 +20,19 @@ SCRIPT_DIR="$(dirname "$0")"
|
|||||||
# // |-- services
|
# // |-- services
|
||||||
# // |-- service name
|
# // |-- service name
|
||||||
# // |-- config
|
# // |-- config
|
||||||
# // |-- service.env
|
# // |-- service.env (actual service config)
|
||||||
|
# // |-- .template_info.env
|
||||||
# // |-- template
|
# // |-- template
|
||||||
|
# // |-- _default.env
|
||||||
# // |-- (script files)
|
# // |-- (script files)
|
||||||
# // |-- config
|
# // |-- config
|
||||||
# // |-- service.env
|
# // |-- service.env (default service config)
|
||||||
|
# // |-- .template_info.env
|
||||||
# // |-- (other config files for specific server&service)
|
# // |-- (other config files for specific server&service)
|
||||||
|
|
||||||
# Get all services on the server
|
# Get all services on the server
|
||||||
SERVICES_PATH=$(realpath "${SCRIPT_DIR}/../services/")
|
SERVICES_PATH=$(realpath "${SCRIPT_DIR}/../services/")
|
||||||
|
|
||||||
|
|
||||||
CURRENT_OUTPUT=""
|
CURRENT_OUTPUT=""
|
||||||
CURRENT_EXIT_CODE=0
|
CURRENT_EXIT_CODE=0
|
||||||
|
|
||||||
@ -40,6 +43,15 @@ load_dotenv(){
|
|||||||
fi
|
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() {
|
function run_command() {
|
||||||
local service_path=$1
|
local service_path=$1
|
||||||
local command=$2
|
local command=$2
|
||||||
@ -55,13 +67,23 @@ function run_command() {
|
|||||||
set -a
|
set -a
|
||||||
load_dotenv "${service_path}/template/_default.env"
|
load_dotenv "${service_path}/template/_default.env"
|
||||||
load_dotenv "${service_path}/config/service.env"
|
load_dotenv "${service_path}/config/service.env"
|
||||||
|
load_dotenv "${service_path}/config/.template_info.env"
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
|
# all_env_vars["CONFIG_PATH"] = remotepath::service_config(server_name,service_name);
|
||||||
|
# all_env_vars["SERVER"] = server_name;
|
||||||
|
# all_env_vars["SERVICE"] = service_name;
|
||||||
|
# all_env_vars["AGENT_PATH"] = remotepath::agent(server_name);
|
||||||
|
# all_env_vars["HOST_NAME"] = server_info.ssh_host;
|
||||||
# update the main variables.
|
# update the main variables.
|
||||||
export CONFIG_PATH="${service_path}/config"
|
export CONFIG_PATH="${service_path}/config"
|
||||||
# SERVER is correct
|
# SERVER is already set
|
||||||
export SERVICE="${SERVICE_NAME}"
|
export SERVICE="${SERVICE_NAME}"
|
||||||
|
export AGENT_PATH="${SCRIPT_DIR}"
|
||||||
|
# HOST_NAME is already set
|
||||||
|
|
||||||
|
_check_required_env_vars_allservicesstatus "CONFIG_PATH" "SERVER" "SERVICE" "AGENT_PATH" "HOST_NAME" "TEMPLATE"
|
||||||
|
|
||||||
if [ "$capture_output" = "true" ]; then
|
if [ "$capture_output" = "true" ]; then
|
||||||
# Capture and return output
|
# Capture and return output
|
||||||
bash "${service_path}/template/${command}.sh" 2>&1
|
bash "${service_path}/template/${command}.sh" 2>&1
|
||||||
|
@ -182,7 +182,7 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string output;
|
std::string output;
|
||||||
if (!execute_ssh_command(env.get_SSH_INFO(), sCommand(remotepath::agent(server_name), "./_allservicesstatus.sh", {}), cMode::CaptureOutput, &output))
|
if (!execute_ssh_command(env.get_SSH_INFO(), sCommand(remotepath::agent(server_name), "./_allservicesstatus.sh", {{"HOST_NAME", server_name}}), cMode::CaptureOutput, &output))
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
std::stringstream ss(output);
|
std::stringstream ss(output);
|
||||||
|
@ -225,15 +225,17 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerInfo server_info = get_server_info(server_name);
|
||||||
|
if (server_info.ssh_host.empty())
|
||||||
|
std::cerr << "Error: Server " << server_name << " not found - ssh_host empty, so HOST_NAME not set" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
// add in some handy variables.
|
// add in some handy variables.
|
||||||
|
// if we change these, we also need to update agent/_allservicesstatus.sh
|
||||||
all_env_vars["CONFIG_PATH"] = remotepath::service_config(server_name,service_name);
|
all_env_vars["CONFIG_PATH"] = remotepath::service_config(server_name,service_name);
|
||||||
all_env_vars["SERVER"] = server_name;
|
all_env_vars["SERVER"] = server_name;
|
||||||
all_env_vars["SERVICE"] = service_name;
|
all_env_vars["SERVICE"] = service_name;
|
||||||
all_env_vars["AGENT_PATH"] = remotepath::agent(server_name);
|
all_env_vars["AGENT_PATH"] = remotepath::agent(server_name);
|
||||||
|
|
||||||
ServerInfo server_info = get_server_info(server_name);
|
|
||||||
if (server_info.ssh_host.empty())
|
|
||||||
std::cerr << "Error: Server " << server_name << " not found - ssh_host empty, so HOST_NAME not set" << std::endl;
|
|
||||||
all_env_vars["HOST_NAME"] = server_info.ssh_host;
|
all_env_vars["HOST_NAME"] = server_info.ssh_host;
|
||||||
|
|
||||||
// Lambda function to load environment variables from a file
|
// Lambda function to load environment variables from a file
|
||||||
|
@ -83,23 +83,27 @@ namespace localpath {
|
|||||||
}
|
}
|
||||||
} // namespace localpath
|
} // namespace localpath
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// remote paths
|
// remote paths
|
||||||
// DROPSHELL_DIR
|
// DROPSHELL_DIR
|
||||||
// |-- backups
|
// |-- backups
|
||||||
// |-- temp_files
|
// |-- temp_files
|
||||||
// |-- agent
|
// |-- agent
|
||||||
|
// | |-- bb64
|
||||||
|
// | |-- (other agent files, including _allservicesstatus.sh)
|
||||||
// |-- services
|
// |-- services
|
||||||
// |-- service name
|
// |-- service name
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env
|
// |-- service.env (actual service config)
|
||||||
// |-- template
|
// |-- template
|
||||||
|
// |-- _default.env
|
||||||
// |-- (script files)
|
// |-- (script files)
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env
|
// |-- service.env (default service config)
|
||||||
// |-- (other config files for specific server&service)
|
// |-- (other config files for specific server&service)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace remotefile {
|
namespace remotefile {
|
||||||
|
|
||||||
std::string service_env(const std::string &server_name, const std::string &service_name)
|
std::string service_env(const std::string &server_name, const std::string &service_name)
|
||||||
|
@ -76,11 +76,14 @@ namespace dropshell {
|
|||||||
// |-- services
|
// |-- services
|
||||||
// |-- service name
|
// |-- service name
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env
|
// |-- service.env (actual service config)
|
||||||
|
// |-- .template_info.env
|
||||||
// |-- template
|
// |-- template
|
||||||
|
// |-- _default.env
|
||||||
// |-- (script files)
|
// |-- (script files)
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env
|
// |-- service.env (default service config)
|
||||||
|
// |-- .template_info.env
|
||||||
// |-- (other config files for specific server&service)
|
// |-- (other config files for specific server&service)
|
||||||
|
|
||||||
namespace remotefile {
|
namespace remotefile {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user