Working on it...
This commit is contained in:
parent
13b1327da7
commit
7a6e77420a
@ -156,27 +156,29 @@ bool server_env::check_remote_items_exist(const std::vector<std::string> &file_p
|
||||
|
||||
bool server_env::execute_ssh_command(const sCommand& command) const {
|
||||
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
||||
bool okay = execute_local_command(full_cmd);
|
||||
return okay;
|
||||
return execute_local_command(full_cmd);
|
||||
}
|
||||
|
||||
bool server_env::execute_ssh_command_and_capture_output(const sCommand& command, std::string &output) const
|
||||
{
|
||||
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
||||
bool okay = execute_local_command_and_capture_output(full_cmd, output);
|
||||
return okay;
|
||||
return execute_local_command_and_capture_output(full_cmd, output);
|
||||
}
|
||||
|
||||
bool server_env::run_remote_template_command(const std::string &service_name, const std::string &command, std::vector<std::string> args, bool silent) const
|
||||
{
|
||||
std::string full_cmd = construct_standard_command_run_cmd(service_name, command, args, silent);
|
||||
bool okay = execute_ssh_command(full_cmd);
|
||||
return okay;
|
||||
return execute_ssh_command(full_cmd);
|
||||
}
|
||||
|
||||
bool server_env::run_remote_template_command_and_capture_output(const std::string &service_name, const std::string &command, std::vector<std::string> args, std::string &output, bool silent) const
|
||||
{
|
||||
std::string full_cmd = construct_standard_command_run_cmd(service_name, command, args, silent);
|
||||
return execute_ssh_command_and_capture_output(full_cmd, output);
|
||||
}
|
||||
|
||||
bool server_env::execute_local_command(const sCommand& command) {
|
||||
bool okay = (system(command.construct_safecmd().c_str()) == 0);
|
||||
return okay;
|
||||
return (system(command.construct_safecmd().c_str()) == 0);
|
||||
}
|
||||
|
||||
bool server_env::execute_local_command_and_capture_output(const sCommand& command, std::string &output)
|
||||
|
@ -61,6 +61,7 @@ class server_env {
|
||||
bool check_remote_items_exist(const std::vector<std::string>& file_paths) const;
|
||||
|
||||
bool run_remote_template_command(const std::string& service_name, const std::string& command, std::vector<std::string> args, bool silent=false) const;
|
||||
bool run_remote_template_command_and_capture_output(const std::string& service_name, const std::string& command, std::vector<std::string> args, std::string & output, bool silent=false) const;
|
||||
|
||||
public:
|
||||
bool execute_ssh_command(const sCommand& command) const;
|
||||
|
@ -18,7 +18,6 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
|
||||
service_runner::service_runner(const std::string& server_name, const std::string& service_name) :
|
||||
m_server_env(server_name), m_server_name(server_name), mValid(false)
|
||||
{
|
||||
@ -227,10 +226,8 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
|
||||
return status;
|
||||
}
|
||||
|
||||
std::string remote_service_template_path = get_remote_service_template_path(server_name, service_name);
|
||||
sCommand scommand(remote_service_template_path, "/bin/bash " + quote(remote_service_template_path + "/" + command + ".sh"), {});
|
||||
std::string output;
|
||||
if (!env.execute_ssh_command_and_capture_output(scommand, output))
|
||||
if (!env.run_remote_template_command_and_capture_output(service_name, command, {}, output))
|
||||
return status;
|
||||
|
||||
std::stringstream ss(output);
|
||||
|
@ -15,9 +15,32 @@ SCRIPT_DIR="$(dirname "$0")"
|
||||
# // |-- service name
|
||||
# // |-- config <-- this is passed as argument to all scripts
|
||||
# // |-- service.env
|
||||
# // |-- (user config files)
|
||||
# // |-- template
|
||||
# // |-- (script files)
|
||||
# // |-- example
|
||||
# // |-- service.env
|
||||
# // |-- (other config files for specific server&service)
|
||||
|
||||
|
||||
function run_command() {
|
||||
local service_path=$1
|
||||
local command=$2
|
||||
|
||||
# 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
|
||||
(
|
||||
source "${service_path}/config/service.env"
|
||||
# SERVER is correct
|
||||
export CONFIG_PATH="${service_path}/config"
|
||||
# update the SERVICE variable
|
||||
export SERVICE="${SERVICE_NAME}"
|
||||
bash "${service_path}/template/${command}.sh" 2>&1
|
||||
)
|
||||
}
|
||||
|
||||
# Get all services on the server
|
||||
SERVICES_PATH="${SCRIPT_DIR}/../../"
|
||||
|
Loading…
x
Reference in New Issue
Block a user