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 {
|
bool server_env::execute_ssh_command(const sCommand& command) const {
|
||||||
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
||||||
bool okay = execute_local_command(full_cmd);
|
return execute_local_command(full_cmd);
|
||||||
return okay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool server_env::execute_ssh_command_and_capture_output(const sCommand& command, std::string &output) const
|
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());
|
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
||||||
bool okay = execute_local_command_and_capture_output(full_cmd, output);
|
return execute_local_command_and_capture_output(full_cmd, output);
|
||||||
return okay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool server_env::run_remote_template_command(const std::string &service_name, const std::string &command, std::vector<std::string> args, bool silent) const
|
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);
|
std::string full_cmd = construct_standard_command_run_cmd(service_name, command, args, silent);
|
||||||
bool okay = execute_ssh_command(full_cmd);
|
return execute_ssh_command(full_cmd);
|
||||||
return okay;
|
}
|
||||||
|
|
||||||
|
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 server_env::execute_local_command(const sCommand& command) {
|
||||||
bool okay = (system(command.construct_safecmd().c_str()) == 0);
|
return (system(command.construct_safecmd().c_str()) == 0);
|
||||||
return okay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool server_env::execute_local_command_and_capture_output(const sCommand& command, std::string &output)
|
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 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(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:
|
public:
|
||||||
bool execute_ssh_command(const sCommand& command) const;
|
bool execute_ssh_command(const sCommand& command) const;
|
||||||
|
@ -18,7 +18,6 @@ namespace fs = std::filesystem;
|
|||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
|
||||||
service_runner::service_runner(const std::string& server_name, const std::string& service_name) :
|
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)
|
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;
|
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;
|
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;
|
return status;
|
||||||
|
|
||||||
std::stringstream ss(output);
|
std::stringstream ss(output);
|
||||||
|
@ -15,9 +15,32 @@ SCRIPT_DIR="$(dirname "$0")"
|
|||||||
# // |-- service name
|
# // |-- service name
|
||||||
# // |-- config <-- this is passed as argument to all scripts
|
# // |-- config <-- this is passed as argument to all scripts
|
||||||
# // |-- service.env
|
# // |-- service.env
|
||||||
# // |-- (user config files)
|
|
||||||
# // |-- template
|
# // |-- template
|
||||||
# // |-- (script files)
|
# // |-- (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
|
# Get all services on the server
|
||||||
SERVICES_PATH="${SCRIPT_DIR}/../../"
|
SERVICES_PATH="${SCRIPT_DIR}/../../"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user