|
|
|
@ -60,14 +60,14 @@ std::string server_env_manager::get_variable(const std::string& name) const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper method implementations
|
|
|
|
|
std::string server_env_manager::construct_ssh_cmd() const {
|
|
|
|
|
std::string server_env_manager::construct_ssh_cmd(bool allocateTTY) const {
|
|
|
|
|
std::stringstream ssh_cmd;
|
|
|
|
|
ssh_cmd << "ssh -p " << get_SSH_PORT() << " "
|
|
|
|
|
ssh_cmd << "ssh -p " << get_SSH_PORT() << " " << (allocateTTY ? "-tt " : "")
|
|
|
|
|
<< get_SSH_USER() << "@" << get_SSH_HOST();
|
|
|
|
|
return ssh_cmd.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string server_env_manager::construct_standard_command_run_cmd(const std::string &service_name, const std::string &command, std::vector<std::string> args, bool silent) const
|
|
|
|
|
sCommand server_env_manager::construct_standard_command_run_cmd(const std::string &service_name, const std::string &command, std::vector<std::string> args, bool silent) const
|
|
|
|
|
{
|
|
|
|
|
std::string remote_service_template_path = remotepath::service_template(mServerName,service_name);
|
|
|
|
|
std::string remote_service_config_path = remotepath::service_config(mServerName,service_name);
|
|
|
|
@ -83,8 +83,7 @@ std::string server_env_manager::construct_standard_command_run_cmd(const std::st
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sCommand scommand(remote_service_template_path, "bash " + quote(script_path) + argstr + (silent ? " > /dev/null 2>&1" : ""), env_vars);
|
|
|
|
|
std::string run_cmd = scommand.construct_safecmd();
|
|
|
|
|
return run_cmd;
|
|
|
|
|
return scommand;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,27 +118,29 @@ bool server_env_manager::check_remote_items_exist(const std::vector<std::string>
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool server_env_manager::execute_ssh_command(const sCommand& command) const {
|
|
|
|
|
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
|
|
|
|
return execute_local_command(full_cmd);
|
|
|
|
|
bool server_env_manager::execute_ssh_command(const sCommand& command, bool allocateTTY) const {
|
|
|
|
|
std::string full_cmd = construct_ssh_cmd(allocateTTY) + " " + (allocateTTY ? halfquote(command.construct_rawcmd()) : quote(command.construct_safecmd()));
|
|
|
|
|
return (system(full_cmd.c_str()) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool server_env_manager::execute_ssh_command_and_capture_output(const sCommand& command, std::string &output) const
|
|
|
|
|
bool server_env_manager::execute_ssh_command_and_capture_output(const sCommand& command, std::string &output, bool allocateTTY) const
|
|
|
|
|
{
|
|
|
|
|
std::string full_cmd = construct_ssh_cmd() + " " + quote(command.construct_safecmd());
|
|
|
|
|
std::string full_cmd = construct_ssh_cmd(allocateTTY) + " " + quote(command.construct_safecmd());
|
|
|
|
|
return execute_local_command_and_capture_output(full_cmd, output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool server_env_manager::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);
|
|
|
|
|
return execute_ssh_command(full_cmd);
|
|
|
|
|
sCommand scommand = construct_standard_command_run_cmd(service_name, command, args, silent);
|
|
|
|
|
bool allocateTTY = (command=="ssh");
|
|
|
|
|
return execute_ssh_command(scommand, allocateTTY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool server_env_manager::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);
|
|
|
|
|
sCommand scommand = construct_standard_command_run_cmd(service_name, command, args, silent);
|
|
|
|
|
bool allocateTTY = (command=="ssh");
|
|
|
|
|
return execute_ssh_command_and_capture_output(scommand, output, allocateTTY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool server_env_manager::execute_local_command(const sCommand& command) {
|
|
|
|
@ -180,6 +181,17 @@ std::string sCommand::construct_safecmd() const
|
|
|
|
|
return commandstr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string sCommand::construct_rawcmd() const
|
|
|
|
|
{
|
|
|
|
|
std::string rawcmd = "cd " + quote(mDir) + " && ";
|
|
|
|
|
|
|
|
|
|
for (const auto& env_var : mVars) {
|
|
|
|
|
rawcmd += env_var.first + "=" + quote(dequote(trim(env_var.second))) + " ";
|
|
|
|
|
}
|
|
|
|
|
rawcmd += mCmd;
|
|
|
|
|
return rawcmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// base64 <<< "FOO=BAR WHEE=YAY bash ./test.sh"
|
|
|
|
|
// echo YmFzaCAtYyAnRk9PPUJBUiBXSEVFPVlBWSBiYXNoIC4vdGVzdC5zaCcK | base64 -d | bash
|
|
|
|
|
|
|
|
|
|