FIx nuke
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-17 18:55:14 +12:00
parent 5bf93dc954
commit 203068048d
3 changed files with 41 additions and 27 deletions

View File

@ -53,27 +53,32 @@ int nuke_one(std::string server, std::string service)
if (!SIvalid(service_info))
std::cerr << "Warning: Invalid service: " << service << std::endl;
// run the nuke script on the remote server if it exists.
// otherwise just uninstall.
if (gTemplateManager().template_command_exists(service_info.template_name, "nuke"))
if (server_env.check_remote_dir_exists(remotepath::service(server, service)))
{
if (!server_env.run_remote_template_command(service, "nuke", {}, false, {}))
std::cerr << "Warning: Failed to run nuke script: " << service << std::endl;
// run the nuke script on the remote server if it exists.
// otherwise just uninstall.
if (gTemplateManager().template_command_exists(service_info.template_name, "nuke"))
{
if (!server_env.run_remote_template_command(service, "nuke", {}, false, {}))
std::cerr << "Warning: Failed to run nuke script: " << service << std::endl;
}
else
{
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
}
// Remove the service directory from the server, running in a docker container as root.
if (server_env.remove_remote_dir(remotepath::service(server, service), true))
{
ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall");
std::cout << "Remote service directory removed: " << remotepath::service(server, service) << std::endl;
}
else
std::cerr << "Warning: Failed to remove remote service directory" << std::endl;
}
else
{
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
std::cerr << "Warning: Failed to uninstall service: " << service << std::endl;
}
// Remove the service directory from the server, running in a docker container as root.
if (server_env.remove_remote_dir(remotepath::service(server, service), true))
{
ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall");
std::cout << "Removed remote service directory " << remotepath::service(server, service) << std::endl;
}
else
std::cerr << "Warning: Failed to remove remote service directory" << std::endl;
std::cerr << "Warning: Service not found on remote server: " << remotepath::service(server, service) << std::endl;
}
else
std::cerr << "Warning: Can't nuke the remote service as the server is invalid: " << server << std::endl;
@ -83,14 +88,17 @@ int nuke_one(std::string server, std::string service)
if (local_service_path.empty() || !std::filesystem::exists(local_service_path))
{
std::cerr << "Warning: Local service directory not found: " << local_service_path << std::endl;
return 1;
}
else
{
auto itemsdeleted = std::filesystem::remove_all(local_service_path);
if (itemsdeleted == 0)
std::cerr << "Error: Failed to remove local service directory" << std::endl;
}
auto ret = std::filesystem::remove_all(local_service_path);
if (ret != 0)
std::cerr << "Warning: Failed to remove local service directory" << std::endl;
std::cout << "Nuked service " << service << " on server " << server << std::endl;
return ret == 0 ? 0 : 1;
return 0;
}
int nuke_handler(const CommandContext &ctx)

View File

@ -183,8 +183,8 @@ bool server_env_manager::remove_remote_dir(const std::string &dir_path, bool sil
"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;
// if (!silent)
// std::cout << "Running command: " << remote_cmd << std::endl;
sCommand scommand("", remote_cmd,{});
cMode mode = (silent ? cMode::Silent : cMode::Defaults);

View File

@ -6,6 +6,7 @@
#include "utils/utils.hpp"
#include "server_env_manager.hpp"
#include "servers.hpp"
#include "assert.hpp"
#include <iostream>
#include <filesystem>
@ -68,6 +69,12 @@ LocalServiceInfo get_service_info(const std::string &server_name, const std::str
if (service.local_service_path.empty())
return LocalServiceInfo();
// check the service directory exists.
if (!fs::exists(service.local_service_path))
{
std::cerr << "Error: Service directory not found: " << service.local_service_path << std::endl;
return LocalServiceInfo();
}
// now set the template name and path.
std::map<std::string, std::string> variables;
@ -221,7 +228,7 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
if (localpath::service(server_name, service_name).empty() || !fs::exists(localpath::service(server_name, service_name)))
{
std::cerr << "Error: Service not found: " << service_name << std::endl;
std::cerr << "Error: Service not found: " << service_name << " on server " << server_name << std::endl;
return false;
}
@ -229,7 +236,6 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
if (server_info.ssh_host.empty())
std::cerr << "Error: Server " << server_name << " not found - ssh_host empty, so HOST_NAME not set" << std::endl;
// add in some handy variables.
// if we change these, we also need to update agent/_allservicesstatus.sh
all_env_vars["CONFIG_PATH"] = remotepath::service_config(server_name,service_name);