Use docker to root remove the local directory.
This commit is contained in:
parent
ce5a64a4c7
commit
b4b237c1b7
@ -217,7 +217,7 @@ int main(int argc, char* argv[]) {
|
||||
// handle running a command.
|
||||
std::set<std::string> commands;
|
||||
get_all_used_commands(commands);
|
||||
commands.merge(std::set<std::string>{"ssh","edit","_allservicesstatus"}); // handled by service_runner, but not in template_shell_commands.
|
||||
commands.merge(std::set<std::string>{"ssh","edit","_allservicesstatus","fullnuke"}); // handled by service_runner, but not in template_shell_commands.
|
||||
|
||||
if (commands.count(cmd)) {
|
||||
std::set<std::string> safe_commands = {"nuke", "fullnuke"};
|
||||
|
@ -156,10 +156,22 @@ bool service_runner::nuke()
|
||||
else
|
||||
{
|
||||
// try uninstalling.
|
||||
mServerEnv.run_remote_template_command(mService, "uninstall", {});
|
||||
mServerEnv.run_remote_template_command(mService, "nuke", {});
|
||||
if (gTemplateManager().template_command_exists(mServiceInfo.template_name, "uninstall"))
|
||||
if (!mServerEnv.run_remote_template_command(mService, "uninstall", {}))
|
||||
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
|
||||
|
||||
std::string rm_cmd = "rm -rf " + quote(remotepath::service(mServer, mService));
|
||||
// try nuke script.
|
||||
if (gTemplateManager().template_command_exists(mServiceInfo.template_name, "nuke"))
|
||||
if (!mServerEnv.run_remote_template_command(mService, "nuke", {}))
|
||||
std::cerr << "Warning: Nuke script failed, but continuing with directory removal" << std::endl;
|
||||
|
||||
// try rm -rf.
|
||||
std::string remotedir = remotepath::service(mServer, mService);
|
||||
std::string remoteparentdir = get_parent(remotedir);
|
||||
std::string remotechilddir = get_child(remotedir);
|
||||
|
||||
std::string cmd = quote("rm -rf /parent/"+remotechilddir);
|
||||
std::string rm_cmd = "docker run --rm -v "+quote(remoteparentdir)+":/parent debian bash -c "+cmd;
|
||||
if (!mServerEnv.execute_ssh_command(rm_cmd)) {
|
||||
std::cerr << "Failed to remove service directory" << std::endl;
|
||||
return false;
|
||||
@ -168,7 +180,6 @@ bool service_runner::nuke()
|
||||
|
||||
std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl;
|
||||
|
||||
|
||||
std::cout << "There's nothing left on the remote server." << std::endl;
|
||||
std::cout << "You can remove the local files with:" << std::endl;
|
||||
std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl;
|
||||
@ -178,9 +189,13 @@ bool service_runner::nuke()
|
||||
|
||||
bool service_runner::fullnuke()
|
||||
{
|
||||
if (!mServerEnv.is_valid()) return false; // should never hit this.
|
||||
if (!nuke())
|
||||
{
|
||||
std::cerr << "Warning: Nuke script failed, aborting fullnuke!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string local_service_path = localpath::service(mServer,mService);
|
||||
std::string local_service_path = mServiceInfo.local_service_path;
|
||||
if (local_service_path.empty() || !fs::exists(local_service_path)) {
|
||||
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl;
|
||||
return false;
|
||||
@ -216,6 +231,9 @@ bool service_runner::run_command(const std::string& command, std::vector<std::st
|
||||
return true;
|
||||
}
|
||||
|
||||
if (command == "fullnuke")
|
||||
return fullnuke();
|
||||
|
||||
if (!gTemplateManager().template_command_exists(mServiceInfo.template_name, command)) {
|
||||
std::cout << "No command script for " << mServiceInfo.template_name << " : " << command << std::endl;
|
||||
return true; // nothing to run.
|
||||
|
@ -153,11 +153,18 @@ namespace remotepath {
|
||||
// ------------------------------------------------------------------------------------------
|
||||
// Utility functions
|
||||
|
||||
std::string get_parent(const std::string &path)
|
||||
std::string get_parent(const std::filesystem::path path)
|
||||
{
|
||||
if (path.empty())
|
||||
return std::string();
|
||||
return fs::path(path).parent_path().string();
|
||||
return path.parent_path().string();
|
||||
}
|
||||
|
||||
std::string get_child(const std::filesystem::path path)
|
||||
{
|
||||
if (path.empty())
|
||||
return std::string();
|
||||
return path.filename().string();
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define DIRECTORIES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
@ -89,8 +90,8 @@ namespace dropshell {
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// utility functions
|
||||
std::string get_parent(const std::string &path);
|
||||
|
||||
std::string get_parent(const std::filesystem::path path);
|
||||
std::string get_child(const std::filesystem::path path);
|
||||
} // namespace dropshell
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user