Compare commits

..

4 Commits

Author SHA1 Message Date
9a141685de Update test.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 12s
2025-05-24 21:27:02 +12:00
9c94510213 .
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 12s
2025-05-24 20:44:21 +12:00
bcc78859fc dropshell release 2025.0524.2033
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 11s
2025-05-24 20:33:55 +12:00
a5243a7e79 Install is broken - putting the wrong template on.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
2025-05-24 20:05:00 +12:00
7 changed files with 105 additions and 48 deletions

View File

@ -14,10 +14,10 @@ jobs:
uses: actions/checkout@v4
- name: Build
run: |
cd ${{ gitea.workspace }}/docker
./compile.sh
cd ${{ gitea.workspace }}/source
./multibuild.sh
- name: Test
run: |
cd ${{ gitea.workspace }}/docker/output
cd ${{ gitea.workspace }}/source/output
./dropshell_x86_64 list
./dropshell_x86_64 help

View File

@ -20,6 +20,15 @@ void CommandRegistry::register_command(const CommandInfo& info) {
const CommandInfo* CommandRegistry::find_command(const std::string& name) const {
auto it = command_map_.find(name);
if (it != command_map_.end()) return it->second.get();
// go deep now.
for (const auto& cmd : all_commands_) {
if (cmd->names.size() > 0) {
for (const auto& altname : cmd->names) {
if (name == altname) return cmd.get();
}
}
}
return nullptr;
}

View File

@ -194,10 +194,10 @@ namespace dropshell
info << "Setting SSH_USER to " << sshuser << " in the " << filenames::service_env << " file" << std::endl;
{ // edit the service.env file to set the SSH_USER.
std::string template_service_env_file = tinfo.local_template_path() / "config" / filenames::service_env;
ASSERT(std::filesystem::exists(template_service_env_file), "Template service env file not found: " + template_service_env_file);
std::ifstream template_service_env_file_in(template_service_env_file);
std::ofstream service_env_file_out(localfile::template_info_env(server_name, service_name));
std::string source_service_env = tinfo.local_template_path() / "config" / filenames::service_env;
ASSERT(std::filesystem::exists(source_service_env), "Template service env file not found: " + source_service_env);
std::ifstream template_service_env_file_in(source_service_env);
std::ofstream service_env_file_out(localfile::service_env(server_name, service_name));
std::string line;
while (std::getline(template_service_env_file_in, line))
{

View File

@ -14,7 +14,7 @@ namespace dropshell
{
int destroy_handler(const CommandContext &ctx);
static std::vector<std::string> destroy_name_list = {"destroy"};
static std::vector<std::string> destroy_name_list = {"destroy", "nuke", "nuke-service","erase","destroy-service"};
// Static registration
struct DestroyCommandRegister
@ -57,65 +57,85 @@ namespace dropshell
// step 1 - destroy on remote server.
if (server_env.is_valid())
{
LocalServiceInfo service_info;
service_info = get_service_info(server, service);
bool service_valid = SIvalid(service_info);
if (!service_valid)
warning << "Invalid service: " << service << std::endl;
std::string user = server_env.get_user_for_service(service);
bool remote_dir_exists = server_env.check_remote_dir_exists(remotepath(server, user).service(service), user);
if (remote_dir_exists)
std::string user = server_env.get_user_for_service(service); // returns empty string if no user found.
if (user.empty())
{
// run the destroy script on the remote server if it exists.
// otherwise just uninstall.
if (service_valid)
warning << "No user found for service " << service << " on " << server << std::endl;
for (auto sshuser : server_env.get_users())
{
if (gTemplateManager().template_command_exists(service_info.template_name, "destroy"))
if (server_env.check_remote_dir_exists(remotepath(server, sshuser.user).service(service), sshuser.user))
{
info << "Running destroy script for " << service << " on " << server << std::endl;
if (!server_env.run_remote_template_command(service, "destroy", {}, false, {}))
warning << "Failed to run destroy script: " << service << std::endl;
info << "Found a remote service directory here: " << remotepath(server, sshuser.user).service(service) << std::endl;
info << "Deleting it as user " << sshuser.user << std::endl;
user = sshuser.user;
break;
}
}
}
if (user.empty())
warning << "No remote service directory found for " << service << " on " << server << std::endl;
else
{ // user is not empty.
LocalServiceInfo service_info;
service_info = get_service_info(server, service);
bool service_valid = SIvalid(service_info);
if (!service_valid)
warning << "No valid service definition found for " << service << std::endl;
if (server_env.check_remote_dir_exists(remotepath(server, user).service(service), user))
{
// run the destroy script on the remote server if it exists.
// otherwise just uninstall.
if (service_valid)
{
if (gTemplateManager().template_command_exists(service_info.template_name, "destroy"))
{
info << "Running destroy script for " << service << " on " << server << std::endl;
if (!server_env.run_remote_template_command(service, "destroy", {}, false, {}))
warning << "Failed to run destroy script: " << service << std::endl;
}
else
{
info << "No destroy script found for " << service << " on " << server << std::endl;
info << "Running uninstall script instead and will clean directories." << std::endl;
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
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(server, user).service(service), true, user))
{
ASSERT(!server_env.check_remote_dir_exists(remotepath(server, user).service(service), user), "Service directory still found on server after uninstall");
info << "Remote service directory removed: " << remotepath(server, user).service(service) << std::endl;
}
else
{
info << "No destroy script found for " << service << " on " << server << std::endl;
info << "Running uninstall script instead and will clean directories." << std::endl;
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
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(server, user).service(service), true, user))
{
ASSERT(!server_env.check_remote_dir_exists(remotepath(server, user).service(service), user), "Service directory still found on server after uninstall");
info << "Remote service directory removed: " << remotepath(server, user).service(service) << std::endl;
warning << "Failed to remove remote service directory" << std::endl;
}
else
warning << "Failed to remove remote service directory" << std::endl;
}
else
warning << "Service not found on remote server: " << remotepath(server, user).service(service) << std::endl;
}
warning << "No remote service directory found for " << service << " on "<< server << std::endl;
} // user is not empty.
} // server_env is valid.
else
warning << "Can't destroy the remote service as the server is invalid: " << server << std::endl;
error << "No valid local server information for server " << server << std::endl;
// step 2 - destroy the local service directory.
// step 2 - destroy the local service directory, if it exists.
std::string local_service_path = localpath::service(server, service);
if (local_service_path.empty() || !std::filesystem::exists(local_service_path))
{
warning << "Local service directory not found: " << local_service_path << std::endl;
warning << "No local service directory found for " << service << " on " << server << std::endl;
}
else
{
auto itemsdeleted = std::filesystem::remove_all(local_service_path);
if (itemsdeleted == 0)
error << "Failed to remove local service directory" << std::endl;
else
info << "Local service directory removed: " << local_service_path << std::endl;
}
info << "Destroyed service " << service << " on server " << server << std::endl;
info << "Finished destroying service " << service << " on server " << server << std::endl;
return true;
}

View File

@ -105,6 +105,16 @@ namespace dropshell
return 1;
}
if (!gTemplateManager().template_command_exists(service_info.template_name, "backup") ||
!gTemplateManager().template_command_exists(service_info.template_name, "restore"))
{
info << service << " has no data to restore" << std::endl;
debug << "(no backup or restore script for " << service_info.template_name << ")" << std::endl;
return 0; // nothing to back up.
}
std::optional<shared_commands::cBackupFileName> backup_details;
if (backup_arg == "latest")
{ // special case.

View File

@ -196,18 +196,36 @@ namespace dropshell
bool ServerConfig::check_remote_dir_exists(const std::string &dir_path, std::string user) const
{
if (user.empty())
{
debug << "Can't check remote directory exists for " << dir_path << " as user is empty" << std::endl;
return false;
}
sCommand scommand("", "test -d " + quote(dir_path), {});
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
}
bool ServerConfig::check_remote_file_exists(const std::string &file_path, std::string user) const
{
if (user.empty())
{
debug << "Can't check remote file exists for " << file_path << " as user is empty" << std::endl;
return false;
}
sCommand scommand("", "test -f " + quote(file_path), {});
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
}
bool ServerConfig::check_remote_items_exist(const std::vector<std::string> &file_paths, std::string user) const
{
if (user.empty())
{
debug << "Can't check remote items exist as user is empty" << std::endl;
return false;
}
// convert file_paths to a single string, separated by spaces
std::string file_paths_str;
std::string file_names_str;

View File

@ -89,7 +89,7 @@ namespace dropshell
// 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;
warning << "Service directory not found: " << service.local_service_path << std::endl;
return LocalServiceInfo();
}