From 898cc97bae1af25cf1bf797386aa68e4ebbeed4e Mon Sep 17 00:00:00 2001 From: John Date: Sun, 27 Apr 2025 11:56:46 +1200 Subject: [PATCH] All fixed! --- src/server_env.cpp | 25 ++++++++++++++++++++----- src/service_runner.cpp | 13 ++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/server_env.cpp b/src/server_env.cpp index 38980c8..1eb27fb 100644 --- a/src/server_env.cpp +++ b/src/server_env.cpp @@ -123,24 +123,39 @@ bool server_env::check_remote_items_exist(const std::vector &file_p } bool server_env::execute_ssh_command(const sCommand& command) const { - std::string full_cmd = construct_ssh_cmd() + command.construct_safecmd(); - return execute_local_command(full_cmd); + std::string full_cmd = construct_ssh_cmd() + quote(command.construct_safecmd()); + bool okay = execute_local_command(full_cmd); + if (!okay) { + std::cerr << "Error: Failed to execute command on remote server: " << full_cmd << std::endl; + } + return okay; } bool server_env::execute_ssh_command_and_capture_output(const sCommand& command, std::string &output) const { - std::string full_cmd = construct_ssh_cmd() + command.construct_safecmd(); - return execute_local_command_and_capture_output(full_cmd, output); + std::string full_cmd = construct_ssh_cmd() + quote(command.construct_safecmd()); + bool okay = execute_local_command_and_capture_output(full_cmd, output); + if (!okay) { + std::cerr << "Error: Failed to execute command on remote server: " << full_cmd << std::endl; + } + return okay; } bool server_env::run_remote_template_command(const std::string &service_name, const std::string &command, std::vector args, bool silent) const { std::string full_cmd = construct_standard_command_run_cmd(service_name, command, args, silent); - return execute_ssh_command(full_cmd); + bool okay = execute_ssh_command(full_cmd); + if (!okay) { + std::cerr << "Error: Failed to execute command on remote server: " << full_cmd << std::endl; + } + return okay; } bool server_env::execute_local_command(const sCommand& command) { bool okay = (system(command.construct_safecmd().c_str()) == 0); + if (!okay) { + std::cerr << "Error: Failed to execute command on local machine: " << command.construct_safecmd() << std::endl; + } return okay; } diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 343e8df..cc427be 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -53,7 +53,7 @@ bool service_runner::install() { std::string mkdir_cmd = "mkdir -p " + quote(mRemote_service_path); if (!m_server_env.execute_ssh_command(mkdir_cmd)) { - std::cerr << "Failed to create service directory" << std::endl; + std::cerr << "Failed to create service directory " << mRemote_service_path << std::endl; return false; } @@ -221,21 +221,16 @@ std::map service_runner::get_all_services_status(std return status; } - std::string remote_service_path = get_remote_service_path(server_name, service_name); - std::string remote_service_config_path = get_remote_service_config_path(server_name, service_name); - 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); - 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 remote_service_template_path = get_remote_service_template_path(server_name, service_name); + sCommand scommand(remote_service_template_path, "/bin/bash " + quote(remote_service_template_path + "/" + command + ".sh"), {}); std::string output; - if (!env.execute_ssh_command_and_capture_output("'cd " + quote(remote_service_template_path) + - " && /bin/bash "+quote(script_path)+"'", output)) + if (!env.execute_ssh_command_and_capture_output(scommand, output)) return status; std::stringstream ss(output);