Back in business
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 18s

This commit is contained in:
Your Name 2025-05-10 21:41:52 +12:00
parent e9d4529d85
commit fe571e1cc9
2 changed files with 37 additions and 37 deletions

View File

@ -71,38 +71,19 @@ bool service_runner::install(bool silent) {
}
// 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(mServer, mService) << "/" << std::endl;
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + mServerEnv.get_SSH_PORT() + "' " +
quote(tinfo.local_template_path().string()+"/") + " "+
mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" +
quote(remotepath::service_template(mServer, mService)+"/");
//std::cout << std::endl << rsync_cmd << std::endl << std::endl;
if (!execute_local_command(rsync_cmd, silent ? cMode::Silent : cMode::None))
{
std::cerr << "Failed to copy template files using rsync" << std::endl;
std::cerr << "Is rsync installed on the remote host?" << std::endl;
return false;
}
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::string local_service_path = localpath::service(mServer,mService);
if (local_service_path.empty() || !fs::exists(local_service_path)) {
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl;
return false;
}
std::cout << "Copying: [LOCAL] " << local_service_path << std::endl <<std::string(8,' ')<<"[REMOTE] " << remotepath::service_config(mServer,mService) << std::endl;
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + mServerEnv.get_SSH_PORT() + "' " +
quote(local_service_path + "/") + " "+
mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" +
quote(remotepath::service_config(mServer,mService) + "/");
if (!execute_local_command(rsync_cmd, silent ? cMode::Silent : cMode::None))
{
std::cerr << "Failed to copy service files using rsync" << std::endl;
return false;
}
std::cerr << "Failed to copy service files using rsync" << std::endl;
return false;
}
// Run install script
@ -289,7 +270,7 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
std::string command = "_allservicesstatus";
std::string service_name = "dropshell-agent";
if (!gTemplateManager().template_command_exists(service_name, command))
if (!gTemplateManager().template_command_exists(service_name, "shared/"+command))
{
std::cerr << "Error: " << service_name << " does not contain the " << command << " script" << std::endl;
return status;
@ -302,7 +283,7 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
}
std::string output;
if (!env.run_remote_template_command_and_capture_output(service_name, command, {}, output, true, {}))
if (!env.run_remote_template_command_and_capture_output(service_name, "shared/"+command, {}, output, true, {}))
return status;
std::stringstream ss(output);
@ -488,7 +469,28 @@ void service_runner::edit_service_config()
std::cout << "To apply your changes, run:\n dropshell install " + mServer + " " + mService << std::endl;
}
bool service_runner::scp_file_to_remote(const std::string &local_path, const std::string &remote_path, bool silent)
{
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " + quote(local_path) + " " + mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remote_path) + (silent ? " > /dev/null 2>&1" : "");
return execute_local_command(scp_cmd, (silent ? cMode::Silent : cMode::None) + cMode::RawCommand);
}
bool service_runner::scp_file_from_remote(const std::string &remote_path, const std::string &local_path, bool silent)
{
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " + mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remote_path) + " " + quote(local_path) + (silent ? " > /dev/null 2>&1" : "");
return execute_local_command(scp_cmd, (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, (silent ? cMode::Silent : cMode::None) + cMode::RawCommand);
}
bool service_runner::restore(std::string backup_file, bool silent)
{
@ -567,9 +569,8 @@ bool service_runner::restore(std::string backup_file, bool silent)
std::string remote_backup_file_path = remote_backups_dir + "/" + backup_file;
// Copy backup file from local to server
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " + quote(local_backup_file_path) + " " + mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remote_backup_file_path) + (silent ? " > /dev/null 2>&1" : "");
if (!execute_local_command(scp_cmd, silent ? cMode::Silent : cMode::None)) {
std::cerr << "Failed to copy backup file from server" << std::endl;
if (!scp_file_to_remote(local_backup_file_path, remote_backup_file_path, silent)) {
std::cerr << "Failed to copy backup file from local to server" << std::endl;
return false;
}
@ -687,10 +688,7 @@ bool service_runner::backup(bool silent) {
}
// Copy backup file from server to local
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " +
mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" +
quote(remote_backup_file_path) + " " + quote(local_backup_file_path) + (silent ? " > /dev/null 2>&1" : "");
if (!execute_local_command(scp_cmd, silent ? cMode::Silent : cMode::None)) {
if (!scp_file_from_remote(remote_backup_file_path, local_backup_file_path, silent)) {
std::cerr << "Failed to copy backup file from server" << std::endl;
return false;
}

View File

@ -87,7 +87,9 @@ class service_runner {
// edit the service configuration file
void edit_service_config();
bool rsync_tree_to_remote(const std::string& local_path, const std::string& remote_path, bool silent=false);
bool scp_file_to_remote(const std::string& local_path, const std::string& remote_path, bool silent=false);
bool scp_file_from_remote(const std::string& remote_path, const std::string& local_path, bool silent=false);
public:
// utility functions
static std::string get_latest_backup_file(const std::string& server, const std::string& service);