execute_ssh_command is not returning the correct return code.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 22s
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 22s
This commit is contained in:
parent
a27dd7638f
commit
df03f5ef91
@ -54,7 +54,7 @@ int nuke_handler(const CommandContext &ctx)
|
|||||||
service_info = get_service_info(server, service);
|
service_info = get_service_info(server, service);
|
||||||
if (!SIvalid(service_info))
|
if (!SIvalid(service_info))
|
||||||
std::cerr << "Warning: Invalid service: " << service << std::endl;
|
std::cerr << "Warning: Invalid service: " << service << std::endl;
|
||||||
else
|
|
||||||
if (!uninstall_service(server, service, false))
|
if (!uninstall_service(server, service, false))
|
||||||
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
|
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
|
||||||
|
|
||||||
@ -64,16 +64,6 @@ int nuke_handler(const CommandContext &ctx)
|
|||||||
if (!server_env.run_remote_template_command(service, "nuke", {}, false, {}))
|
if (!server_env.run_remote_template_command(service, "nuke", {}, false, {}))
|
||||||
std::cerr << "Warning: Failed to run nuke script: " << service << std::endl;
|
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
|
else
|
||||||
std::cerr << "Warning: Invalid server: " << server << std::endl;
|
std::cerr << "Warning: Invalid server: " << server << std::endl;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include "command_registry.hpp"
|
#include "command_registry.hpp"
|
||||||
#include "directories.hpp"
|
#include "directories.hpp"
|
||||||
#include "shared_commands.hpp"
|
#include "shared_commands.hpp"
|
||||||
|
#include "templates.hpp"
|
||||||
|
|
||||||
|
#include <libassert/assert.hpp>
|
||||||
|
|
||||||
namespace dropshell
|
namespace dropshell
|
||||||
{
|
{
|
||||||
@ -80,29 +83,24 @@ namespace dropshell
|
|||||||
|
|
||||||
// 3. Run uninstall script if it exists
|
// 3. Run uninstall script if it exists
|
||||||
std::string uninstall_script = remotepath::service_template(server, service) + "/uninstall.sh";
|
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 (script_exists)
|
|
||||||
{
|
|
||||||
if (!server_env.run_remote_template_command(service, "uninstall", {}, silent, {}))
|
if (!server_env.run_remote_template_command(service, "uninstall", {}, silent, {}))
|
||||||
if (!silent)
|
if (!silent)
|
||||||
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
|
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!silent)
|
|
||||||
std::cerr << "Warning: No uninstall script found, continuing with direcotry removal." << std::endl;
|
|
||||||
|
|
||||||
// 4. Remove the service directory from the server
|
// 4. Remove the service directory from the server, running in a docker container as root.
|
||||||
std::string rm_cmd = "rm -rf " + quote(remotepath::service(server, service));
|
if (server_env.remove_remote_dir(remotepath::service(server, service), silent))
|
||||||
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand(rm_cmd), cMode::Silent))
|
|
||||||
{
|
{
|
||||||
|
ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall");
|
||||||
if (!silent)
|
if (!silent)
|
||||||
std::cerr << "Failed to remove service directory" << std::endl;
|
std::cout << "Removed remote service directory " << remotepath::service(server, service) << std::endl;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
else if (!silent)
|
||||||
|
std::cerr << "Warning: Failed to remove remote service directory" << std::endl;
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
std::cout << "Service " << service << " successfully uninstalled from " << server << std::endl;
|
std::cout << "Completed service " << service << " uninstall on " << server << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,33 @@ bool server_env_manager::check_remote_items_exist(const std::vector<std::string>
|
|||||||
return true;
|
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
|
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);
|
sCommand scommand = construct_standard_template_run_cmd(service_name, command, args, silent);
|
||||||
|
@ -53,6 +53,8 @@ class server_env_manager {
|
|||||||
bool check_remote_file_exists(const std::string& file_path) const;
|
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 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,
|
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;
|
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,
|
bool run_remote_template_command_and_capture_output(const std::string& service_name, const std::string& command,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user