diff --git a/source/src/commands/create-service.cpp b/source/src/commands/create-service.cpp index 66b4033..ce1c762 100644 --- a/source/src/commands/create-service.cpp +++ b/source/src/commands/create-service.cpp @@ -11,7 +11,6 @@ namespace dropshell { int create_service_handler(const CommandContext &ctx); - bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name); void create_service_autocomplete(const CommandContext &ctx); static std::vector create_service_name_list = {"create-service"}; @@ -45,7 +44,7 @@ namespace dropshell std::string service = safearg(ctx.args, 1); std::string template_name = safearg(ctx.args, 2); - return create_service(server, template_name, service) ? 0 : 1; + return shared_commands::create_service(server, template_name, service) ? 0 : 1; } void create_service_autocomplete(const CommandContext &ctx) @@ -63,6 +62,9 @@ namespace dropshell } } + namespace shared_commands + { + bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name) { if (server_name.empty() || template_name.empty() || service_name.empty()) @@ -117,4 +119,6 @@ namespace dropshell return true; } + } // namespace shared_commands + } // namespace dropshell \ No newline at end of file diff --git a/source/src/commands/nuke.cpp b/source/src/commands/nuke.cpp index dc52de1..f388042 100644 --- a/source/src/commands/nuke.cpp +++ b/source/src/commands/nuke.cpp @@ -61,7 +61,7 @@ namespace dropshell service_info = get_service_info(server, service); if (!SIvalid(service_info)) - error << "Warning: Invalid service: " << service << std::endl; + error << "Invalid service: " << service << std::endl; if (server_env.check_remote_dir_exists(remotepath::service(server, service))) { diff --git a/source/src/commands/restoredata.cpp b/source/src/commands/restoredata.cpp index 6c66f10..43b964c 100644 --- a/source/src/commands/restoredata.cpp +++ b/source/src/commands/restoredata.cpp @@ -174,8 +174,20 @@ namespace dropshell return 1; } + { // create the new service + info << "3) Creating new service..." << std::endl; + if (!shared_commands::create_service(server, service_info.template_name, service)) + return 1; + } + + { // installing fresh service + info << "4) Install of fresh service..." << std::endl; + if (!shared_commands::install_service(server, service)) + return 1; + } + { // restore service from backup - info << "3) Restoring service data from backup..." << std::endl; + info << "5) Restoring service data from backup..." << std::endl; std::string remote_backups_dir = remotepath::backups(server); std::string remote_backup_file_path = remote_backups_dir + "/" + backup_details->get_filename(); @@ -190,11 +202,7 @@ namespace dropshell server_env.run_remote_template_command(service, "restore", {}, false, {{"BACKUP_FILE", remote_backup_file_path}, {"TEMP_DIR", remote_temp_folder.path()}}); } // dtor of remote_temp_folder will clean up the temp folder on the server - { // installing fresh service - info << "4) Non-destructive install of fresh service..." << std::endl; - if (!shared_commands::install_service(server, service)) - return 1; - } + { // healthcheck the service info << "5) Healthchecking service..." << std::endl; diff --git a/source/src/commands/shared_commands.hpp b/source/src/commands/shared_commands.hpp index c11bf6d..ccb7598 100644 --- a/source/src/commands/shared_commands.hpp +++ b/source/src/commands/shared_commands.hpp @@ -93,6 +93,9 @@ namespace dropshell // defined in install.cpp bool install_service(const std::string &server, const std::string &service); + // defined in create-service.cpp + bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name); + } // namespace shared_commands } // namespace dropshell #endif diff --git a/source/src/config.cpp b/source/src/config.cpp index 4588eac..3612b42 100644 --- a/source/src/config.cpp +++ b/source/src/config.cpp @@ -6,6 +6,9 @@ #include "utils/json.hpp" #include #include "utils/execute.hpp" +#include "output.hpp" + + namespace dropshell { @@ -150,7 +153,7 @@ std::vector config::get_local_server_definition_paths() { if (path.is_string() && !path.empty()) paths.push_back(path); else - std::cerr << "Warning: Invalid server definition path: " << path << std::endl; + warning << "Invalid server definition path: " << path << std::endl; } return paths; } diff --git a/source/src/service_runner.cpp b/source/src/service_runner.cpp index 2660b8f..0d7f1fa 100644 --- a/source/src/service_runner.cpp +++ b/source/src/service_runner.cpp @@ -121,12 +121,12 @@ bool service_runner::nuke(bool silent) std::string remote_service_path = remotepath::service(mServer, mService); - std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl; + info << "Service " << mService << " successfully nuked from " << mServer << std::endl; if (!silent) { - 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; + info << "There's nothing left on the remote server." << std::endl; + info << "You can remove the local files with:" << std::endl; + info << " rm -rf " << localpath::service(mServer,mService) << std::endl; } return true; } @@ -135,19 +135,19 @@ bool service_runner::fullnuke() { if (!nuke(true)) { - std::cerr << "Warning: Nuke script failed, aborting fullnuke!" << std::endl; + warning << "Nuke script failed, aborting." << std::endl; return false; } 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; + error << "Service directory not found: " << local_service_path << std::endl; return false; } std::string rm_cmd = "rm -rf " + quote(local_service_path); if (!execute_local_command("", rm_cmd, {}, nullptr, cMode::Silent)) { - std::cerr << "Failed to remove service directory" << std::endl; + error << "Failed to remove service directory" << std::endl; return false; } diff --git a/source/src/services.cpp b/source/src/services.cpp index 7cd62f2..0775d5b 100644 --- a/source/src/services.cpp +++ b/source/src/services.cpp @@ -47,7 +47,7 @@ std::vector get_server_services_info(const std::string& server if (!service.local_service_path.empty()) services.push_back(service); else - std::cerr << "Warning: Failed to get service info for " << dirname << " on server " << server_name << std::endl; + warning << "Failed to get service info for " << dirname << " on server " << server_name << std::endl; } } // end of for } @@ -188,7 +188,7 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string all_env_vars.merge(env_vars); } else - std::cout << "Warning: Expected environment file not found: " << file << std::endl; + warning << "Expected environment file not found: " << file << std::endl; }; // Load environment files @@ -198,11 +198,10 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string // determine template name. auto it = all_env_vars.find("TEMPLATE"); if (it == all_env_vars.end()) { - std::cerr << std::endl << std::endl; - std::cerr << "Error: TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; - std::cerr << "The TEMPLATE variable is required to determine the template name." << std::endl; - std::cerr << "Please check the service.env file and the .template_info.env file in:" << std::endl; - std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl; + error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; + info << "The TEMPLATE variable is required to determine the template name." << std::endl; + info << "Please check the service.env file and the .template_info.env file in:" << std::endl; + info << " " << localpath::service(server_name, service_name) << std::endl << std::endl; return false; } template_info tinfo = gTemplateManager().get_template_info(it->second); diff --git a/source/src/utils/directories.cpp b/source/src/utils/directories.cpp index d3016cb..3393ca8 100644 --- a/source/src/utils/directories.cpp +++ b/source/src/utils/directories.cpp @@ -1,10 +1,13 @@ #include "directories.hpp" #include "config.hpp" #include "server_env_manager.hpp" +#include "output.hpp" + #include #include #include + namespace fs = std::filesystem; namespace dropshell { @@ -78,7 +81,7 @@ namespace localpath { std::filesystem::path homedir_path(homedir); return fs::canonical(homedir_path).string(); } - std::cerr << "Warning: Couldn't determine user directory" << std::endl; + warning << "Couldn't determine user directory" << std::endl; return std::string(); } } // namespace localpath