From 866046b50559d555abaefdcf0e176fc210bf8d9f Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 May 2025 20:13:21 +1200 Subject: [PATCH] Nuke! --- src/service_runner.cpp | 47 +++++++++++++++++++++++++ src/service_runner.hpp | 3 ++ templates/dropshell-agent/install.sh | 2 +- templates/dropshell-agent/nuke.sh | 6 ++++ templates/example-nginx/nuke.sh | 14 ++++++++ templates/example-nginx/uninstall.sh | 2 +- templates/simple-object-storage/nuke.sh | 12 +++++++ 7 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 templates/dropshell-agent/nuke.sh create mode 100644 templates/example-nginx/nuke.sh create mode 100644 templates/simple-object-storage/nuke.sh diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 5a66e19..0d48cb7 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -144,6 +144,48 @@ bool service_runner::uninstall() { return true; } +bool service_runner::nuke() +{ + maketitle("Nuking " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); + + if (!mServerEnv.is_valid()) return false; // should never hit this. + + // 2. Check if service directory exists on server + if (!mServerEnv.check_remote_dir_exists(remotepath::service(mServer, mService))) + std::cerr << "Service is not installed: " << mService << std::endl; + else + { + // try uninstalling. + mServerEnv.run_remote_template_command(mService, "uninstall", {}); + mServerEnv.run_remote_template_command(mService, "nuke", {}); + + std::string rm_cmd = "rm -rf " + quote(remotepath::service(mServer, mService)); + if (!mServerEnv.execute_ssh_command(rm_cmd)) { + std::cerr << "Failed to remove service directory" << std::endl; + return false; + } + } + + std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl; + std::cout << "Now deleteing local files..." << std::endl; + std::string local_service_path = localpath::service(mServer,mService); + if (local_service_path.empty() || !fs::exists(local_service_path)) { + std::cerr << "Error: Service directory not found: " << local_service_path << std::endl; + } + else + { + std::string rm_cmd = "rm -rf " + quote(local_service_path); + if (!mServerEnv.execute_local_command(rm_cmd)) { + std::cerr << "Failed to remove service directory" << std::endl; + return false; + } + } + + std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl; + return true; +} + + // ------------------------------------------------------------------------------------------------ // Run a command on the service. @@ -193,6 +235,10 @@ bool service_runner::run_command(const std::string& command, std::vector