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 {
|
bool server_service::execute_ssh_command(const std::string& command, const std::string& error_msg) const {
|
||||||
std::string full_cmd = construct_ssh_cmd() + command;
|
std::string full_cmd = construct_ssh_cmd() + command;
|
||||||
|
return execute_local_command(full_cmd, error_msg);
|
||||||
bool okay = (system(full_cmd.c_str()) == 0);
|
}
|
||||||
|
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())
|
if (!okay && !error_msg.empty())
|
||||||
std::cerr << "Error: " << error_msg << std::endl;
|
std::cerr << "Error: " << error_msg << std::endl;
|
||||||
@ -160,12 +162,10 @@ bool server_service::install() {
|
|||||||
// Copy template files
|
// Copy template files
|
||||||
std::cout << "Copying template files from " << info.path << " to " << script_dir << "/" << std::endl;
|
std::cout << "Copying template files from " << info.path << " to " << script_dir << "/" << std::endl;
|
||||||
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env->get_SSH_PORT() + "' " +
|
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env->get_SSH_PORT() + "' " +
|
||||||
info.path + "/ " +
|
info.path + "/ " +
|
||||||
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
||||||
script_dir + "/";
|
script_dir + "/";
|
||||||
if (!execute_ssh_command(rsync_cmd, "Failed to copy template files")) {
|
execute_local_command(rsync_cmd,"Failed to copy template files");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy service env file
|
// Copy service env file
|
||||||
std::string user_dir;
|
std::string user_dir;
|
||||||
@ -185,7 +185,13 @@ bool server_service::install() {
|
|||||||
// Run install script
|
// Run install script
|
||||||
std::string install_cmd = "'cd " + script_dir +
|
std::string install_cmd = "'cd " + script_dir +
|
||||||
" && /bin/bash _install.sh " + get_env_path() + "'";
|
" && /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) {
|
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() + " " +
|
std::string scp_cmd = "scp -P " + m_server_env->get_SSH_PORT() + " " +
|
||||||
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
m_server_env->get_SSH_USER() + "@" + m_server_env->get_SSH_HOST() + ":" +
|
||||||
server_backup_path + " " + local_backup_path;
|
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;
|
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'","");
|
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
|
} // namespace dropshell
|
@ -50,6 +50,8 @@ class server_service {
|
|||||||
// 2. return the output of the status.sh script
|
// 2. return the output of the status.sh script
|
||||||
bool is_healthy();
|
bool is_healthy();
|
||||||
|
|
||||||
|
std::string healthtick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_server_name;
|
std::string m_server_name;
|
||||||
std::string m_service_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_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 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_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
|
} // namespace dropshell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user