Integrate in agent.

This commit is contained in:
Your Name
2025-04-25 20:06:47 +12:00
parent 513431b7a3
commit 9409adf4f6
10 changed files with 306 additions and 130 deletions

View File

@ -3,6 +3,9 @@
// manage a service on a server
//
#ifndef SERVICE_RUNNER_HPP
#define SERVICE_RUNNER_HPP
#include <string>
#include <vector>
#include <memory>
@ -11,6 +14,19 @@
namespace dropshell {
typedef enum HealthStatus {
HEALTHY,
UNHEALTHY,
NOTINSTALLED,
ERROR,
UNKNOWN
} HealthStatus;
typedef struct ServiceStatus {
HealthStatus health;
std::vector<int> ports;
} ServiceStatus;
class service_runner {
public:
service_runner();
@ -30,13 +46,7 @@ class service_runner {
// check health of service. Silent.
// 1. run status.sh on the server
// 2. return the output of the status.sh script
enum class HealthStatus {
HEALTHY,
UNHEALTHY,
NOTINSTALLED,
ERROR,
UNKNOWN
};
HealthStatus is_healthy();
// get the ports of the service
@ -47,6 +57,9 @@ class service_runner {
std::string healthtick();
std::string healthmark();
// get the status of all services on the server
static std::map<std::string, ServiceStatus> get_all_services_status(std::string server_name);
static std::string HealthStatus2String(HealthStatus status);
private:
// install the service over ssh, using the credentials from server.env (via server_env.hpp), by:
@ -73,6 +86,7 @@ class service_runner {
bool backup();
private:
std::string m_server_name;
ServiceInfo m_service_info;
@ -84,12 +98,18 @@ class service_runner {
std::string mRemote_service_env_file;
// Helper methods
static std::string construct_ssh_cmd(const server_env &env);
std::string construct_ssh_cmd() 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;
bool execute_ssh_command(const std::string& command, const std::string& error_msg) const;
bool execute_local_command(const std::string& command, const std::string& error_msg) const;
static bool execute_local_command_and_capture_output(const std::string& command, std::string & output);
};
} // namespace dropshell
#endif // SERVICE_RUNNER_HPP