From 25bc0b46553f14c2fe4ef604e396f4b7cf809fc7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 11 May 2025 13:54:13 +1200 Subject: [PATCH] ./ --- src/commands/health.cpp | 64 ++++++++++++++++++++++++++++++ src/commands/install.cpp | 2 +- src/commands/shared_commands.hpp | 3 ++ src/service_runner.cpp | 68 ++------------------------------ 4 files changed, 71 insertions(+), 66 deletions(-) create mode 100644 src/commands/health.cpp diff --git a/src/commands/health.cpp b/src/commands/health.cpp new file mode 100644 index 0000000..8ff0d6e --- /dev/null +++ b/src/commands/health.cpp @@ -0,0 +1,64 @@ +#include "command_registry.hpp" +#include "config.hpp" +#include "utils/utils.hpp" +#include "service_runner.hpp" +#include "utils/directories.hpp" +#include "standard_autocomplete.hpp" +#include "templates.hpp" +#include "shared_commands.hpp" + + +namespace dropshell { + + int health_handler(const CommandContext& ctx); + void health_autocomplete(const CommandContext& ctx); + + static std::vector health_name_list={"health","check","healthcheck","status"}; + + // Static registration + struct HealthCommandRegister { + HealthCommandRegister() { + CommandRegistry::instance().register_command({ + health_name_list, + health_handler, + health_autocomplete, + false, // hidden + false, // requires_config + 1, // min_args (after command) + 2, // max_args (after command) + "health SERVER", + "Check the health of a server.", + R"( + health + )" + }); + } + } health_command_register; + + + // ------------------------------------------------------------------------------------------------ + // health command implementation + + std::string healthtick(const std::string& server, const std::string& service) { + return "OK"; + } + + // ------------------------------------------------------------------------------------------------ + // health command implementation + // ------------------------------------------------------------------------------------------------ + int health_handler(const CommandContext& ctx) { + if (ctx.args.size() < 1) { + + } + return 0; + } + + // ------------------------------------------------------------------------------------------------ + // health autocomplete + // ------------------------------------------------------------------------------------------------ + void health_autocomplete(const CommandContext& ctx) { + if (ctx.args.size() == 1) { + + } + } +} // namespace dropshell diff --git a/src/commands/install.cpp b/src/commands/install.cpp index b318db0..6c04501 100644 --- a/src/commands/install.cpp +++ b/src/commands/install.cpp @@ -128,7 +128,7 @@ bool install_service(const std::string& server, const std::string& service, bool } // print health tick - std::cout << "Health: " << healthtick() << std::endl; + std::cout << "Health: " << healthtick(server,service) << std::endl; return true; } diff --git a/src/commands/shared_commands.hpp b/src/commands/shared_commands.hpp index e5fee20..6414f0c 100644 --- a/src/commands/shared_commands.hpp +++ b/src/commands/shared_commands.hpp @@ -15,5 +15,8 @@ namespace dropshell { // defined in install.cpp bool install_service(const std::string& server, const std::string& service, bool silent); + // defined in health.cpp + std::string healthtick(const std::string& server, const std::string& service); + } // namespace dropshell #endif diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 9087b69..4403450 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -17,6 +17,7 @@ #include "utils/directories.hpp" #include "utils/utils.hpp" #include "command_registry.hpp" +#include "shared_commands.hpp" namespace fs = std::filesystem; @@ -43,58 +44,6 @@ service_runner::service_runner(const std::string& server_name, const std::string mValid = !mServiceInfo.local_template_path.empty(); } -bool service_runner::install(bool silent) { - maketitle("Installing " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); - - if (!mServerEnv.is_valid()) return false; // should never hit this. - - // Check if template exists - template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name); - if (!tinfo.is_set()) - return false; - - // Create service directory - std::string remote_service_path = remotepath::service(mServer, mService); - std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path); - if (!execute_ssh_command(mServerEnv.get_SSH_INFO(), sCommand(mkdir_cmd), cMode::Silent)) - { - std::cerr << "Failed to create service directory " << remote_service_path << std::endl; - return false; - } - - // Check if rsync is installed on remote host - std::string check_rsync_cmd = "which rsync"; - if (!execute_ssh_command(mServerEnv.get_SSH_INFO(), sCommand(check_rsync_cmd), cMode::Silent)) - { - std::cerr << "rsync is not installed on the remote host" << std::endl; - return false; - } - - // Copy template files - std::cout << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(mServer, mService) << "/" << std::endl; - if (!rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath::service_template(mServer, mService), silent)) - { - std::cerr << "Failed to copy template files using rsync" << std::endl; - return false; - } - - // Copy service files - std::cout << "Copying: [LOCAL] " << localpath::service(mServer,mService) << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_config(mServer,mService) << std::endl; - if (!rsync_tree_to_remote(localpath::service(mServer,mService), remotepath::service_config(mServer,mService), silent)) - { - std::cerr << "Failed to copy service files using rsync" << std::endl; - return false; - } - - // Run install script - { - mServerEnv.run_remote_template_command(mService, "install", {}, silent, {}); - } - - // print health tick - std::cout << "Health: " << healthtick() << std::endl; - return true; -} bool service_runner::uninstall(bool silent) { maketitle("Uninstalling " + mService + " (" + mServiceInfo.template_name + ") on " + mServer); @@ -210,7 +159,7 @@ bool service_runner::run_command(const std::string& command, std::vector