Backups working again

This commit is contained in:
Your Name 2025-04-25 20:46:10 +12:00
parent d0b7c27af3
commit 84c252c965
4 changed files with 23 additions and 14 deletions

View File

@ -63,6 +63,14 @@ std::string service_runner::construct_ssh_cmd() const
return construct_ssh_cmd(*m_server_env);
}
std::string service_runner::construct_standard_command_run_cmd(const std::string &command) const
{
std::string script_path = mRemote_service_template_path + "/" + command + ".sh";
std::string run_cmd = "'cd " + quote(mRemote_service_template_path) +
" && /bin/bash "+quote(script_path)+" "+quote(mRemote_service_config_path)+"'";
return run_cmd;
}
bool service_runner::check_remote_dir_exists(const std::string &dir_path) const
{
std::string check_dir_cmd = construct_ssh_cmd() + "'test -d " + quote(dir_path) + "'";
@ -176,8 +184,7 @@ bool service_runner::install() {
// Run install script
{
std::string install_cmd = "'cd " + quote(mRemote_service_template_path) +
" && /bin/bash install.sh " + quote(mRemote_service_config_path) + "'";
std::string install_cmd = construct_standard_command_run_cmd("install");
bool ok= execute_ssh_command(install_cmd, "Failed to run install script");
if (!ok)
return false;
@ -204,8 +211,7 @@ bool service_runner::uninstall() {
bool script_exists = check_remote_file_exists(uninstall_script);
if (script_exists) {
std::string uninstall_cmd = "'cd " + quote(mRemote_service_template_path) +
" && /bin/bash "+quote(uninstall_script)+" "+quote(mRemote_service_config_path)+"'";
std::string uninstall_cmd = construct_standard_command_run_cmd("uninstall");
if (!execute_ssh_command(uninstall_cmd, "Failed to run uninstall script")) {
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
}
@ -266,8 +272,7 @@ bool service_runner::run_command(const std::string& command) {
return backup();
// Run the generic command
std::string run_cmd = "'cd " + quote(mRemote_service_template_path) +
" && /bin/bash "+quote(script_path)+" "+quote(mRemote_service_config_path)+"'";
std::string run_cmd = construct_standard_command_run_cmd(command);
return execute_ssh_command(run_cmd, "Command returned error code: " + script_path);
}
@ -276,7 +281,7 @@ bool service_runner::backup() {
if (!m_server_env) return false; // should never hit this.
std::string command = "_backup";
std::string command = "backup";
std::string script_path = mRemote_service_template_path + "/" + command + ".sh";
if (!template_command_exists(m_service_info.template_name, command)) {
@ -322,8 +327,11 @@ bool service_runner::backup() {
// Run backup script
std::string backup_cmd = "'cd " + quote(mRemote_service_template_path) +
" && /bin/bash "+quote(script_path)+" "+quote(mRemote_service_env_file)+" "+quote(server_backup_path)+"'";
" && /bin/bash "+quote(script_path)+" "+quote(mRemote_service_config_path)+" "+
quote(server_backup_path)+"'";
if (!execute_ssh_command(backup_cmd, "Backup script failed")) {
std::cerr << "Backup script failed: " << backup_cmd << std::endl;
return false;
}
@ -357,15 +365,13 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
std::string remote_service_template_path = get_remote_service_template_path(server_name, service_name);
std::string remote_service_env_file = get_remote_service_env_file(server_name, service_name);
std::string script_path = remote_service_template_path + "/" + command + ".sh";
server_env env(server_name);
if (!env.is_valid()) {
std::cerr << "Error: Invalid server environment" << std::endl;
return status;
}
std::string script_path = remote_service_template_path + "/" + command + ".sh";
std::string ssh_cmd = construct_ssh_cmd(env) + "'cd " + quote(remote_service_template_path) +
" && /bin/bash "+quote(script_path)+" "+quote(remote_service_config_path)+"'";
@ -428,7 +434,8 @@ HealthStatus service_runner::is_healthy()
}
// Run status script, does not display output.
bool ok = execute_ssh_command("'cd " + mRemote_service_template_path + " && /bin/bash " + script_path + " " + mRemote_service_config_path + " > /dev/null 2>&1'", "");
std::string run_cmd = construct_standard_command_run_cmd("status");
bool ok = execute_ssh_command(run_cmd, "");
if (!ok)
return HealthStatus::UNHEALTHY;

View File

@ -96,6 +96,8 @@ class service_runner {
static std::string construct_ssh_cmd(const server_env &env);
std::string construct_ssh_cmd() const;
std::string construct_standard_command_run_cmd(const std::string& command) const;
bool check_remote_dir_exists(const std::string& dir_path) const;
bool check_remote_file_exists(const std::string& file_path) const;
bool check_remote_items_exist(const std::vector<std::string>& file_paths) const;

View File

@ -40,7 +40,7 @@ load_env() {
env_file="$1/service.env"
if [ ! -f "$env_file" ]; then
echo "Warning: service.env file not found in $1"
echo "Warning: service.env file not found at $1/service.env"
return 1
fi

View File

@ -40,7 +40,7 @@ load_env() {
env_file="$1/service.env"
if [ ! -f "$env_file" ]; then
echo "Warning: service.env file not found in $1"
echo "Warning: service.env file not found at $1/service.env"
return 1
fi