Nuke!
This commit is contained in:
parent
ec779e51c2
commit
866046b505
@ -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<std::st
|
||||
|
||||
if (command == "uninstall")
|
||||
return uninstall();
|
||||
|
||||
if (command == "nuke")
|
||||
return nuke();
|
||||
|
||||
if (command == "ssh") {
|
||||
interactive_ssh_service();
|
||||
return true;
|
||||
@ -531,6 +577,7 @@ bool service_runner::restore(std::string backup_file, bool silent)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool name_breaks_backups(std::string name)
|
||||
{
|
||||
// if name contains -_-, return true
|
||||
|
@ -84,6 +84,9 @@ class service_runner {
|
||||
bool backup(bool silent=false);
|
||||
bool restore(std::string backup_file, bool silent=false);
|
||||
|
||||
// nuke the service
|
||||
bool nuke();
|
||||
|
||||
// launch an interactive ssh session on a server or service
|
||||
// replaces the current dropshell process with the ssh process
|
||||
void interactive_ssh_service();
|
||||
|
@ -18,7 +18,7 @@ install_prerequisites() {
|
||||
# - wget
|
||||
# - docker
|
||||
|
||||
PREREQUISITES=("bash" "curl" "wget" "docker")
|
||||
PREREQUISITES=("bash" "curl" "wget" "jq" "docker")
|
||||
|
||||
# check if all prerequisites are installed
|
||||
for prerequisite in "${PREREQUISITES[@]}"; do
|
||||
|
6
templates/dropshell-agent/nuke.sh
Normal file
6
templates/dropshell-agent/nuke.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NUKE SCRIPT
|
||||
# run after uninstall.sh to delete all data.
|
||||
|
||||
|
14
templates/example-nginx/nuke.sh
Normal file
14
templates/example-nginx/nuke.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NUKE SCRIPT
|
||||
# This is run after the uninstall.sh script to delete all data.
|
||||
# dropshell handles the configuration files, so we just need to remove
|
||||
# any docker volumes and any custom local data folders.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
|
||||
|
||||
# remove the local data folder
|
||||
rm -rf $LOCAL_DATA_FOLDER || die "Failed to remove local data folder ${LOCAL_DATA_FOLDER}"
|
||||
|
||||
echo "Nuking of ${CONTAINER_NAME} complete."
|
@ -6,7 +6,7 @@
|
||||
# It is called with the path to the server specific env file as an argument.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
|
||||
|
||||
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
||||
_is_container_running && die "Couldn't stop existing container"
|
||||
|
12
templates/simple-object-storage/nuke.sh
Normal file
12
templates/simple-object-storage/nuke.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NUKE SCRIPT
|
||||
# Gets run after uninstall.sh
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
|
||||
|
||||
docker volume rm $VOLUME_NAME || die "Failed to remove volume ${VOLUME_NAME}"
|
||||
|
||||
echo "Nuking of ${CONTAINER_NAME} complete."
|
||||
|
Loading…
x
Reference in New Issue
Block a user