Health tick
This commit is contained in:
parent
3c96da9e18
commit
7d1db266b0
@ -121,8 +121,10 @@ bool server_service::check_remote_file_exists(const std::string& ssh_cmd, const
|
||||
|
||||
bool server_service::execute_ssh_command(const std::string& command, const std::string& error_msg) const {
|
||||
std::string full_cmd = construct_ssh_cmd() + command;
|
||||
|
||||
bool okay = (system(full_cmd.c_str()) == 0);
|
||||
return execute_local_command(full_cmd, error_msg);
|
||||
}
|
||||
bool server_service::execute_local_command(const std::string& command, const std::string& error_msg) const {
|
||||
bool okay = (system(command.c_str()) == 0);
|
||||
|
||||
if (!okay && !error_msg.empty())
|
||||
std::cerr << "Error: " << error_msg << std::endl;
|
||||
@ -163,9 +165,7 @@ bool server_service::install() {
|
||||
info.path + "/ " +
|
||||
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
||||
script_dir + "/";
|
||||
if (!execute_ssh_command(rsync_cmd, "Failed to copy template files")) {
|
||||
return false;
|
||||
}
|
||||
execute_local_command(rsync_cmd,"Failed to copy template files");
|
||||
|
||||
// Copy service env file
|
||||
std::string user_dir;
|
||||
@ -185,7 +185,13 @@ bool server_service::install() {
|
||||
// Run install script
|
||||
std::string install_cmd = "'cd " + script_dir +
|
||||
" && /bin/bash _install.sh " + get_env_path() + "'";
|
||||
return execute_ssh_command(install_cmd, "Failed to run install script");
|
||||
bool ok= execute_ssh_command(install_cmd, "Failed to run install script");
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
// print health tick
|
||||
std::cout << "Health: " << healthtick() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool server_service::run_command(const std::string& command) {
|
||||
@ -273,7 +279,7 @@ bool server_service::backup() {
|
||||
std::string scp_cmd = "scp -P " + m_server_env->get_SSH_PORT() + " " +
|
||||
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
||||
server_backup_path + " " + local_backup_path;
|
||||
if (!execute_ssh_command(scp_cmd, "Failed to copy backup file from server")) {
|
||||
if (!execute_local_command(scp_cmd, "Failed to copy backup file from server")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -296,4 +302,15 @@ bool server_service::is_healthy()
|
||||
return execute_ssh_command("'cd " + script_dir + " && /bin/bash status.sh " + env_path + " > /dev/null 2>&1'","");
|
||||
}
|
||||
|
||||
std::string server_service::healthtick()
|
||||
{
|
||||
std::string green_tick = "\033[32m✓\033[0m";
|
||||
std::string red_cross = "\033[31m✗\033[0m";
|
||||
|
||||
if (is_healthy())
|
||||
return green_tick;
|
||||
else
|
||||
return red_cross;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
@ -50,6 +50,8 @@ class server_service {
|
||||
// 2. return the output of the status.sh script
|
||||
bool is_healthy();
|
||||
|
||||
std::string healthtick();
|
||||
|
||||
private:
|
||||
std::string m_server_name;
|
||||
std::string m_service_name;
|
||||
@ -63,6 +65,7 @@ class server_service {
|
||||
bool check_service_dir_exists(const std::string& ssh_cmd) const;
|
||||
bool check_remote_file_exists(const std::string& ssh_cmd, const std::string& file_path) 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;
|
||||
};
|
||||
|
||||
} // namespace dropshell
|
||||
|
Loading…
x
Reference in New Issue
Block a user