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

This commit is contained in:
Your Name 2025-05-11 13:47:51 +12:00
parent 72df234290
commit 64639adcf0
4 changed files with 62 additions and 12 deletions

View File

@ -5,6 +5,8 @@
#include "utils/directories.hpp"
#include "standard_autocomplete.hpp"
#include "templates.hpp"
#include "shared_commands.hpp"
#include <unistd.h>
#include <cstring>
#include <iostream>
@ -46,22 +48,49 @@ struct InstallCommandRegister {
// ------------------------------------------------------------------------------------------------
// install service over ssh
// rsync_tree_to_remote : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool rsync_tree_to_remote(
const std::string &local_path,
const std::string &remote_path,
server_env_manager &server_env,
bool silent)
{
ASSERT(!local_path.empty() && !remote_path.empty());
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
quote(local_path + "/") + " "+
quote(server_env.get_SSH_USER() + "@" + server_env.get_SSH_HOST() + ":" +
remote_path + "/");
return execute_local_command(rsync_cmd, nullptr, (silent ? cMode::Silent : cMode::None) + cMode::RawCommand);
}
// ------------------------------------------------------------------------------------------------
// install service over ssh : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool install_service(const std::string& server, const std::string& service, bool silent) {
maketitle("Installing " + mService + " (" + mServiceInfo.template_name + ") on " + mServer);
LocalServiceInfo service_info = get_service_info(server, service);
if (!SIvalid(service_info))
return false;
if (!mServerEnv.is_valid()) return false; // should never hit this.
server_env_manager server_env(server);
if (!server_env.is_valid())
return false;
maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server);
if (!server_env.is_valid()) return false; // should never hit this.
// Check if template exists
template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name);
template_info tinfo = gTemplateManager().get_template_info(service_info.template_name);
if (!tinfo.is_set())
return false;
// Create service directory
std::string remote_service_path = remotepath::service(mServer, mService);
std::string remote_service_path = remotepath::service(server, service);
std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path);
if (!execute_ssh_command(mServerEnv.get_SSH_INFO(), sCommand(mkdir_cmd), cMode::Silent))
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand(mkdir_cmd), cMode::Silent))
{
std::cerr << "Failed to create service directory " << remote_service_path << std::endl;
return false;
@ -69,23 +98,25 @@ bool install_service(const std::string& server, const std::string& service, bool
// 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))
if (!execute_ssh_command(server_env.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::cout << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(server, service) << "/" << std::endl;
if (!rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath::service_template(server, service),
server_env, 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::cout << "Copying: [LOCAL] " << localpath::service(server,service) << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_config(server,service) << std::endl;
if (!rsync_tree_to_remote(localpath::service(server,service), remotepath::service_config(server,service),
server_env, silent))
{
std::cerr << "Failed to copy service files using rsync" << std::endl;
return false;
@ -93,7 +124,7 @@ bool install_service(const std::string& server, const std::string& service, bool
// Run install script
{
mServerEnv.run_remote_template_command(mService, "install", {}, silent, {});
server_env.run_remote_template_command(service, "install", {}, silent, {});
}
// print health tick

View File

@ -0,0 +1,19 @@
#ifndef SHARED_COMMANDS_HPP
#define SHARED_COMMANDS_HPP
#include "servers.hpp"
namespace dropshell {
// defined in install.cpp
bool rsync_tree_to_remote(
const std::string &local_path,
const std::string &remote_path,
server_env_manager &server_env,
bool silent);
// defined in install.cpp
bool install_service(const std::string& server, const std::string& service, bool silent);
} // namespace dropshell
#endif