diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 08a802e..73cc6f0 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -39,7 +39,7 @@ service_runner::service_runner(const std::string& server_name, const std::string mValid = !mServiceInfo.local_template_path.empty(); } -bool service_runner::install() { +bool service_runner::install(bool silent) { maketitle("Installing " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); if (!mServerEnv.is_valid()) return false; // should never hit this. @@ -111,7 +111,7 @@ bool service_runner::install() { return true; } -bool service_runner::uninstall() { +bool service_runner::uninstall(bool silent) { maketitle("Uninstalling " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); 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; { // backup existing service - std::cout << "1) Backing up existing service... " << std::flush; + maketitle("1) Backing up old service... "); if (!backup(true)) // silent=true { std::cerr << std::endl; @@ -580,8 +580,19 @@ bool service_runner::restore(std::string backup_file, bool silent) 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 - 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_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); } // dtor of remote_temp_folder will clean up the temp folder on the server - // healthcheck the service - std::cout << "3) Healthchecking service..." << std::endl; - std::string green_tick = "\033[32m✓\033[0m"; - std::string red_cross = "\033[31m✗\033[0m"; - bool healthy= (mServerEnv.run_remote_template_command(mService, "status", {}, silent)); - if (!silent) - std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl; - return true; + { // 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 red_cross = "\033[31m✗\033[0m"; + healthy= (mServerEnv.run_remote_template_command(mService, "status", {}, silent)); + if (!silent) + std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl; + } + + return healthy; } diff --git a/src/service_runner.hpp b/src/service_runner.hpp index 88b66d7..b1b5511 100644 --- a/src/service_runner.hpp +++ b/src/service_runner.hpp @@ -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) // 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 - bool install(); + bool install(bool silent=false); // 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 // 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 // 4. remove the service directory from the server - bool uninstall(); + bool uninstall(bool silent=false); // backup and restore bool backup(bool silent=false); diff --git a/templates/squashkiwi/start.sh b/templates/squashkiwi/start.sh index 5f39d7e..54a6bac 100644 --- a/templates/squashkiwi/start.sh +++ b/templates/squashkiwi/start.sh @@ -12,6 +12,7 @@ DOCKER_RUN_CMD="docker run -d \ if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then + echo "${DOCKER_RUN_CMD}" _die "Failed to start container ${CONTAINER_NAME}" fi diff --git a/templates/test_template.sh b/templates/test_template.sh index 4c86cc3..a760952 100755 --- a/templates/test_template.sh +++ b/templates/test_template.sh @@ -55,6 +55,9 @@ title "Checking template $TEMPLATE" SERVICE_NAME="test-$TEMPLATE" +title "Nuking old service" +ds fullnuke localhost $SERVICE_NAME || die "Failed to fullnuke old service" + title "Creating service" ds create-service localhost $TEMPLATE $SERVICE_NAME || die "Failed to create service"