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.
|
// handle running a command.
|
||||||
std::set<std::string> commands;
|
std::set<std::string> commands;
|
||||||
get_all_used_commands(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)) {
|
if (commands.count(cmd)) {
|
||||||
std::set<std::string> safe_commands = {"nuke", "fullnuke"};
|
std::set<std::string> safe_commands = {"nuke", "fullnuke"};
|
||||||
|
@ -156,10 +156,22 @@ bool service_runner::nuke()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// try uninstalling.
|
// try uninstalling.
|
||||||
mServerEnv.run_remote_template_command(mService, "uninstall", {});
|
if (gTemplateManager().template_command_exists(mServiceInfo.template_name, "uninstall"))
|
||||||
mServerEnv.run_remote_template_command(mService, "nuke", {});
|
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)) {
|
if (!mServerEnv.execute_ssh_command(rm_cmd)) {
|
||||||
std::cerr << "Failed to remove service directory" << std::endl;
|
std::cerr << "Failed to remove service directory" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -168,7 +180,6 @@ bool service_runner::nuke()
|
|||||||
|
|
||||||
std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl;
|
std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl;
|
||||||
|
|
||||||
|
|
||||||
std::cout << "There's nothing left on the remote server." << 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 << "You can remove the local files with:" << std::endl;
|
||||||
std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl;
|
std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl;
|
||||||
@ -178,9 +189,13 @@ bool service_runner::nuke()
|
|||||||
|
|
||||||
bool service_runner::fullnuke()
|
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)) {
|
if (local_service_path.empty() || !fs::exists(local_service_path)) {
|
||||||
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl;
|
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -216,6 +231,9 @@ bool service_runner::run_command(const std::string& command, std::vector<std::st
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command == "fullnuke")
|
||||||
|
return fullnuke();
|
||||||
|
|
||||||
if (!gTemplateManager().template_command_exists(mServiceInfo.template_name, command)) {
|
if (!gTemplateManager().template_command_exists(mServiceInfo.template_name, command)) {
|
||||||
std::cout << "No command script for " << mServiceInfo.template_name << " : " << command << std::endl;
|
std::cout << "No command script for " << mServiceInfo.template_name << " : " << command << std::endl;
|
||||||
return true; // nothing to run.
|
return true; // nothing to run.
|
||||||
|
@ -153,11 +153,18 @@ namespace remotepath {
|
|||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
std::string get_parent(const std::string &path)
|
std::string get_parent(const std::filesystem::path path)
|
||||||
{
|
{
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
return std::string();
|
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
|
} // namespace dropshell
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define DIRECTORIES_HPP
|
#define DIRECTORIES_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
@ -89,8 +90,8 @@ namespace dropshell {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// utility functions
|
// 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
|
} // namespace dropshell
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user