All tests pass for squashkiwi

This commit is contained in:
Your Name 2025-05-06 00:03:46 +12:00
parent 38cb23706d
commit 01858d8601
4 changed files with 38 additions and 14 deletions

View File

@ -39,7 +39,7 @@ service_runner::service_runner(const std::string& server_name, const std::string
mValid = !mServiceInfo.local_template_path.empty(); mValid = !mServiceInfo.local_template_path.empty();
} }
bool service_runner::install() { bool service_runner::install(bool silent) {
maketitle("Installing " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); maketitle("Installing " + mService + " (" + mServiceInfo.template_name + ") on " + mServer);
if (!mServerEnv.is_valid()) return false; // should never hit this. if (!mServerEnv.is_valid()) return false; // should never hit this.
@ -111,7 +111,7 @@ bool service_runner::install() {
return true; return true;
} }
bool service_runner::uninstall() { bool service_runner::uninstall(bool silent) {
maketitle("Uninstalling " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); maketitle("Uninstalling " + mService + " (" + mServiceInfo.template_name + ") on " + mServer);
if (!mServerEnv.is_valid()) return false; // should never hit this. if (!mServerEnv.is_valid()) return false; // should never hit this.
@ -568,7 +568,7 @@ bool service_runner::restore(std::string backup_file, bool silent)
std::cout << "OK, here goes..." << std::endl; std::cout << "OK, here goes..." << std::endl;
{ // backup existing service { // backup existing service
std::cout << "1) Backing up existing service... " << std::flush; maketitle("1) Backing up old service... ");
if (!backup(true)) // silent=true if (!backup(true)) // silent=true
{ {
std::cerr << std::endl; std::cerr << std::endl;
@ -580,8 +580,19 @@ bool service_runner::restore(std::string backup_file, bool silent)
std::cout << "Backup complete." << std::endl; std::cout << "Backup complete." << std::endl;
} }
{ // uninstall service, then nuke it.
maketitle("2) Uninstalling old service...");
if (!uninstall(true))
return false;
maketitle("3) Nuking old service...");
if (!nuke(true))
return false;
}
{ // restore service from backup { // restore service from backup
std::cout << "2) Restoring service from backup..." << std::endl; maketitle("4) Restoring service data from backup...");
std::string remote_backups_dir = remotepath::backups(mServer); std::string remote_backups_dir = remotepath::backups(mServer);
std::string remote_backup_file_path = remote_backups_dir + "/" + backup_file; std::string remote_backup_file_path = remote_backups_dir + "/" + backup_file;
@ -596,15 +607,24 @@ bool service_runner::restore(std::string backup_file, bool silent)
mServerEnv.run_remote_template_command(mService, "restore", {remote_backup_file_path, remote_temp_folder.path()}, silent); mServerEnv.run_remote_template_command(mService, "restore", {remote_backup_file_path, remote_temp_folder.path()}, silent);
} // dtor of remote_temp_folder will clean up the temp folder on the server } // dtor of remote_temp_folder will clean up the temp folder on the server
// healthcheck the service
std::cout << "3) Healthchecking service..." << std::endl; { // installing fresh service
maketitle("5) Non-destructive install of fresh service...");
if (!install(true))
return false;
}
bool healthy = false;
{// healthcheck the service
maketitle("6) Healthchecking service...");
std::string green_tick = "\033[32m✓\033[0m"; std::string green_tick = "\033[32m✓\033[0m";
std::string red_cross = "\033[31m✗\033[0m"; std::string red_cross = "\033[31m✗\033[0m";
bool healthy= (mServerEnv.run_remote_template_command(mService, "status", {}, silent)); healthy= (mServerEnv.run_remote_template_command(mService, "status", {}, silent));
if (!silent) if (!silent)
std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl; std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl;
}
return true; return healthy;
} }

View File

@ -64,14 +64,14 @@ class service_runner {
// 3. copy the template files into {DROPSHELL_DIR}/{service_name}/template (from the templates directory for the specified server, using templates.hpp to identify the path) // 3. copy the template files into {DROPSHELL_DIR}/{service_name}/template (from the templates directory for the specified server, using templates.hpp to identify the path)
// 4. copying the local service directory into {DROPSHELL_DIR}/{service_name}/config (from the server directory for the specified server) // 4. copying the local service directory into {DROPSHELL_DIR}/{service_name}/config (from the server directory for the specified server)
// 5. running the install.sh script on the server, passing the {service_name}.env file as an argument // 5. running the install.sh script on the server, passing the {service_name}.env file as an argument
bool install(); bool install(bool silent=false);
// uninstall the service over ssh, using the credentials from server.env (via server_env.hpp) // uninstall the service over ssh, using the credentials from server.env (via server_env.hpp)
// 1. check if the server_name exists, and the service_name refers to a valid template // 1. check if the server_name exists, and the service_name refers to a valid template
// 2. check if service_name is valid for the server_name // 2. check if service_name is valid for the server_name
// 3. run the uninstall.sh script on the server, passing the {service_name}.env file as an argument // 3. run the uninstall.sh script on the server, passing the {service_name}.env file as an argument
// 4. remove the service directory from the server // 4. remove the service directory from the server
bool uninstall(); bool uninstall(bool silent=false);
// backup and restore // backup and restore
bool backup(bool silent=false); bool backup(bool silent=false);

View File

@ -12,6 +12,7 @@ DOCKER_RUN_CMD="docker run -d \
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
echo "${DOCKER_RUN_CMD}"
_die "Failed to start container ${CONTAINER_NAME}" _die "Failed to start container ${CONTAINER_NAME}"
fi fi

View File

@ -55,6 +55,9 @@ title "Checking template $TEMPLATE"
SERVICE_NAME="test-$TEMPLATE" SERVICE_NAME="test-$TEMPLATE"
title "Nuking old service"
ds fullnuke localhost $SERVICE_NAME || die "Failed to fullnuke old service"
title "Creating service" title "Creating service"
ds create-service localhost $TEMPLATE $SERVICE_NAME || die "Failed to create service" ds create-service localhost $TEMPLATE $SERVICE_NAME || die "Failed to create service"