feat: Update 14 and remove 1 files
This commit is contained in:
@@ -303,10 +303,12 @@ namespace dropshell
|
||||
const std::string &command,
|
||||
std::vector<std::string> args,
|
||||
bool silent,
|
||||
std::map<std::string, std::string> extra_env_vars) const
|
||||
std::map<std::string, std::string> extra_env_vars,
|
||||
std::string * output
|
||||
) const
|
||||
{
|
||||
std::string user = get_user_for_service(service_name);
|
||||
auto scommand = construct_standard_template_run_cmd(service_name, command, args, silent);
|
||||
auto scommand = construct_standard_template_run_cmd(service_name, command, args);
|
||||
if (!scommand.has_value())
|
||||
return false;
|
||||
|
||||
@@ -317,28 +319,7 @@ namespace dropshell
|
||||
if (scommand->get_command_to_run().empty())
|
||||
return false;
|
||||
cMode mode = (command == "ssh") ? (cMode::Interactive) : (silent ? cMode::Silent : cMode::Defaults);
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand.value(), mode);
|
||||
}
|
||||
|
||||
bool ServerConfig::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,
|
||||
std::map<std::string, std::string> extra_env_vars) const
|
||||
{
|
||||
std::string user = get_user_for_service(service_name);
|
||||
auto scommand = construct_standard_template_run_cmd(service_name, command, args, false);
|
||||
if (!scommand.has_value())
|
||||
return false;
|
||||
|
||||
// add the extra env vars to the command
|
||||
for (const auto &[key, value] : extra_env_vars)
|
||||
scommand->add_env_var(key, value);
|
||||
|
||||
// Use Silent mode when capturing output to avoid printing to console
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand.value(), cMode::Silent, &output);
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand.value(), mode, output);
|
||||
}
|
||||
|
||||
std::string ServerConfig::get_variable(const std::string &name) const
|
||||
@@ -351,41 +332,19 @@ namespace dropshell
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::optional<sCommand> ServerConfig::construct_standard_template_run_cmd(const std::string &service_name, const std::string &command, const std::vector<std::string> args, const bool silent) const
|
||||
std::optional<sCommand> ServerConfig::construct_standard_template_run_cmd(const std::string &service_name, const std::string &command, const std::vector<std::string> args) const
|
||||
{
|
||||
if (command.empty())
|
||||
return std::nullopt;
|
||||
|
||||
std::string user = get_user_for_service(service_name);
|
||||
|
||||
std::string remote_service_template_path = remotepath(mServerName, user).service_template(service_name);
|
||||
std::string script_path = remote_service_template_path + "/" + command + ".sh";
|
||||
|
||||
ordered_env_vars env_vars;
|
||||
if (!get_all_service_env_vars(mServerName, service_name, env_vars))
|
||||
{
|
||||
error << "Failed to get all service env vars for " << service_name << std::endl;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
set_var(env_vars, "HOST_NAME", get_SSH_HOST());
|
||||
|
||||
std::string argstr = "";
|
||||
for (const auto &arg : args)
|
||||
{
|
||||
argstr += " " + quote(dequote(trim(arg)));
|
||||
}
|
||||
|
||||
sCommand sc(
|
||||
remote_service_template_path,
|
||||
quote(script_path) + argstr + (silent ? " > /dev/null 2>&1" : ""),
|
||||
env_vars);
|
||||
|
||||
if (sc.empty())
|
||||
{
|
||||
error << "Failed to construct command for " << service_name << " " << command << std::endl;
|
||||
return std::nullopt;
|
||||
}
|
||||
argstr += " " + requote(arg);
|
||||
|
||||
std::string dsrun = remotefile(mServerName, user).ds_run();
|
||||
sCommand sc("", dsrun + " " + requote(service_name) + " " + requote(command) + argstr, {});
|
||||
return sc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user