dropshell release 2025.0518.2236
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-18 22:37:00 +12:00
parent d80820db15
commit cf8738aee9
8 changed files with 45 additions and 25 deletions

View File

@ -11,7 +11,6 @@ namespace dropshell
{ {
int create_service_handler(const CommandContext &ctx); 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); void create_service_autocomplete(const CommandContext &ctx);
static std::vector<std::string> create_service_name_list = {"create-service"}; static std::vector<std::string> create_service_name_list = {"create-service"};
@ -45,7 +44,7 @@ namespace dropshell
std::string service = safearg(ctx.args, 1); std::string service = safearg(ctx.args, 1);
std::string template_name = safearg(ctx.args, 2); 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) 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) 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()) if (server_name.empty() || template_name.empty() || service_name.empty())
@ -117,4 +119,6 @@ namespace dropshell
return true; return true;
} }
} // namespace shared_commands
} // namespace dropshell } // namespace dropshell

View File

@ -61,7 +61,7 @@ namespace dropshell
service_info = get_service_info(server, service); service_info = get_service_info(server, service);
if (!SIvalid(service_info)) 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))) if (server_env.check_remote_dir_exists(remotepath::service(server, service)))
{ {

View File

@ -174,8 +174,20 @@ namespace dropshell
return 1; 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 { // 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_backups_dir = remotepath::backups(server);
std::string remote_backup_file_path = remote_backups_dir + "/" + backup_details->get_filename(); 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()}}); 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 } // 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 { // healthcheck the service
info << "5) Healthchecking service..." << std::endl; info << "5) Healthchecking service..." << std::endl;

View File

@ -93,6 +93,9 @@ namespace dropshell
// defined in install.cpp // defined in install.cpp
bool install_service(const std::string &server, const std::string &service); 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 shared_commands
} // namespace dropshell } // namespace dropshell
#endif #endif

View File

@ -6,6 +6,9 @@
#include "utils/json.hpp" #include "utils/json.hpp"
#include <filesystem> #include <filesystem>
#include "utils/execute.hpp" #include "utils/execute.hpp"
#include "output.hpp"
namespace dropshell { namespace dropshell {
@ -150,7 +153,7 @@ std::vector<std::string> config::get_local_server_definition_paths() {
if (path.is_string() && !path.empty()) if (path.is_string() && !path.empty())
paths.push_back(path); paths.push_back(path);
else else
std::cerr << "Warning: Invalid server definition path: " << path << std::endl; warning << "Invalid server definition path: " << path << std::endl;
} }
return paths; return paths;
} }

View File

@ -121,12 +121,12 @@ bool service_runner::nuke(bool silent)
std::string remote_service_path = remotepath::service(mServer, mService); 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) { if (!silent) {
std::cout << "There's nothing left on the remote server." << std::endl; info << "There's nothing left on the remote server." << std::endl;
std::cout << "You can remove the local files with:" << std::endl; info << "You can remove the local files with:" << std::endl;
std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl; info << " rm -rf " << localpath::service(mServer,mService) << std::endl;
} }
return true; return true;
} }
@ -135,19 +135,19 @@ bool service_runner::fullnuke()
{ {
if (!nuke(true)) if (!nuke(true))
{ {
std::cerr << "Warning: Nuke script failed, aborting fullnuke!" << std::endl; warning << "Nuke script failed, aborting." << std::endl;
return false; return false;
} }
std::string local_service_path = mServiceInfo.local_service_path; 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; error << "Service directory not found: " << local_service_path << std::endl;
return false; return false;
} }
std::string rm_cmd = "rm -rf " + quote(local_service_path); std::string rm_cmd = "rm -rf " + quote(local_service_path);
if (!execute_local_command("", rm_cmd, {}, nullptr, cMode::Silent)) { 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; return false;
} }

View File

@ -47,7 +47,7 @@ std::vector<LocalServiceInfo> get_server_services_info(const std::string& server
if (!service.local_service_path.empty()) if (!service.local_service_path.empty())
services.push_back(service); services.push_back(service);
else 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 } // 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); all_env_vars.merge(env_vars);
} }
else else
std::cout << "Warning: Expected environment file not found: " << file << std::endl; warning << "Expected environment file not found: " << file << std::endl;
}; };
// Load environment files // Load environment files
@ -198,11 +198,10 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
// determine template name. // determine template name.
auto it = all_env_vars.find("TEMPLATE"); auto it = all_env_vars.find("TEMPLATE");
if (it == all_env_vars.end()) { if (it == all_env_vars.end()) {
std::cerr << std::endl << std::endl; error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
std::cerr << "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;
std::cerr << "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;
std::cerr << "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;
std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl;
return false; return false;
} }
template_info tinfo = gTemplateManager().get_template_info(it->second); template_info tinfo = gTemplateManager().get_template_info(it->second);

View File

@ -1,10 +1,13 @@
#include "directories.hpp" #include "directories.hpp"
#include "config.hpp" #include "config.hpp"
#include "server_env_manager.hpp" #include "server_env_manager.hpp"
#include "output.hpp"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace dropshell { namespace dropshell {
@ -78,7 +81,7 @@ namespace localpath {
std::filesystem::path homedir_path(homedir); std::filesystem::path homedir_path(homedir);
return fs::canonical(homedir_path).string(); 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(); return std::string();
} }
} // namespace localpath } // namespace localpath