execute_ssh_command is not returning the correct return code.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 22s

This commit is contained in:
Your Name 2025-05-11 21:33:49 +12:00
parent a27dd7638f
commit df03f5ef91
4 changed files with 47 additions and 30 deletions

View File

@ -54,9 +54,9 @@ int nuke_handler(const CommandContext &ctx)
service_info = get_service_info(server, service);
if (!SIvalid(service_info))
std::cerr << "Warning: Invalid service: " << service << std::endl;
else
if (!uninstall_service(server, service, false))
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
if (!uninstall_service(server, service, false))
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
// run the nuke script on the remote server if it exists.
if (gTemplateManager().template_command_exists(service_info.template_name, "nuke"))
@ -64,16 +64,6 @@ int nuke_handler(const CommandContext &ctx)
if (!server_env.run_remote_template_command(service, "nuke", {}, false, {}))
std::cerr << "Warning: Failed to run nuke script: " << service << std::endl;
}
// remove the remote service directory, running in a docker container as root.
std::string rm_cmd = "docker run --rm -v " + quote(remotepath::service(server, service)) + ":/service alpine rm -rf /service";
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand(rm_cmd), cMode::Silent))
{
std::cerr << "Warning: Failed to remove remote service directory" << std::endl;
std::cerr << "You may need to log in and delete it manually." << std::endl;
std::cerr << " ssh " << server << std::endl;
std::cerr << " rm -rf " << remotepath::service(server, service) << std::endl;
}
}
else
std::cerr << "Warning: Invalid server: " << server << std::endl;

View File

@ -1,6 +1,9 @@
#include "command_registry.hpp"
#include "directories.hpp"
#include "shared_commands.hpp"
#include "templates.hpp"
#include <libassert/assert.hpp>
namespace dropshell
{
@ -80,29 +83,24 @@ namespace dropshell
// 3. Run uninstall script if it exists
std::string uninstall_script = remotepath::service_template(server, service) + "/uninstall.sh";
bool script_exists = server_env.check_remote_file_exists(uninstall_script);
if (gTemplateManager().template_command_exists(service, "uninstall"))
if (server_env.check_remote_file_exists(uninstall_script))
if (!server_env.run_remote_template_command(service, "uninstall", {}, silent, {}))
if (!silent)
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
if (script_exists)
// 4. Remove the service directory from the server, running in a docker container as root.
if (server_env.remove_remote_dir(remotepath::service(server, service), silent))
{
if (!server_env.run_remote_template_command(service, "uninstall", {}, silent, {}))
if (!silent)
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
}
else
ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall");
if (!silent)
std::cerr << "Warning: No uninstall script found, continuing with direcotry removal." << std::endl;
// 4. Remove the service directory from the server
std::string rm_cmd = "rm -rf " + quote(remotepath::service(server, service));
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand(rm_cmd), cMode::Silent))
{
if (!silent)
std::cerr << "Failed to remove service directory" << std::endl;
return false;
std::cout << "Removed remote service directory " << remotepath::service(server, service) << std::endl;
}
else if (!silent)
std::cerr << "Warning: Failed to remove remote service directory" << std::endl;
if (!silent)
std::cout << "Service " << service << " successfully uninstalled from " << server << std::endl;
std::cout << "Completed service " << service << " uninstall on " << server << std::endl;
return true;
}

View File

@ -161,6 +161,33 @@ bool server_env_manager::check_remote_items_exist(const std::vector<std::string>
return true;
}
bool server_env_manager::remove_remote_dir(const std::string &dir_path, bool silent) const
{
std::filesystem::path path(dir_path);
std::filesystem::path parent_path = path.parent_path();
std::string target_dir = path.filename().string();
if (parent_path.empty())
parent_path="/";
if (target_dir.empty())
return false;
if (!silent)
std::cout << "Removing remote directory " << target_dir << " in " << parent_path << " on " << mServerName << std::endl;
std::string remote_cmd =
"docker run --rm -v " + quote(parent_path.string()) + ":/parent " +
" alpine rm -rf \"/parent/" + target_dir + "\"";
if (!silent)
std::cout << "Running command: " << remote_cmd << std::endl;
sCommand scommand(remote_cmd);
cMode mode = (silent ? cMode::Silent : cMode::None);
return execute_ssh_command(get_SSH_INFO(), scommand, mode);
}
bool server_env_manager::run_remote_template_command(const std::string &service_name, const std::string &command, std::vector<std::string> args, bool silent, std::map<std::string, std::string> extra_env_vars) const
{
sCommand scommand = construct_standard_template_run_cmd(service_name, command, args, silent);

View File

@ -53,6 +53,8 @@ class server_env_manager {
bool check_remote_file_exists(const std::string& file_path) const;
bool check_remote_items_exist(const std::vector<std::string>& file_paths) const;
bool remove_remote_dir(const std::string &dir_path, bool silent) const;
bool run_remote_template_command(const std::string& service_name, const std::string& command,
std::vector<std::string> args, bool silent, std::map<std::string, std::string> extra_env_vars) const;
bool run_remote_template_command_and_capture_output(const std::string& service_name, const std::string& command,