./
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 21s

This commit is contained in:
Your Name 2025-05-11 13:54:13 +12:00
parent 64639adcf0
commit 25bc0b4655
4 changed files with 71 additions and 66 deletions

64
src/commands/health.cpp Normal file
View File

@ -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<std::string> 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 <server>
)"
});
}
} 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

View File

@ -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;
}

View File

@ -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

View File

@ -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<std::st
// install doesn't require anything on the server yet.
if (command == "install")
return install();
return install_service(mServer, mService, false);
std::string script_path = remotepath::service_template(mServer, mService) + "/" + command + ".sh";
@ -417,17 +366,6 @@ bool service_runner::scp_file_from_remote(const std::string &remote_path, const
return execute_local_command(scp_cmd, nullptr, (silent ? cMode::Silent : cMode::None) + cMode::RawCommand);
}
bool service_runner::rsync_tree_to_remote(const std::string &local_path, const std::string &remote_path, bool silent)
{
ASSERT(!local_path.empty() && !remote_path.empty());
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + mServerEnv.get_SSH_PORT() + "' " +
quote(local_path + "/") + " "+
quote(mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" +
remote_path + "/");
return execute_local_command(rsync_cmd, nullptr, (silent ? cMode::Silent : cMode::None) + cMode::RawCommand);
}
bool service_runner::restore(std::string backup_file, bool silent)
{
if (backup_file.empty()) {
@ -517,7 +455,7 @@ bool service_runner::restore(std::string backup_file, bool silent)
{ // installing fresh service
maketitle("5) Non-destructive install of fresh service...");
if (!install(true))
if (!install_service(mServer, mService, true))
return false;
}