.
This commit is contained in:
parent
005fbbecbe
commit
3fa5d5076a
@ -67,9 +67,6 @@ dropshell help
|
|||||||
# Show version
|
# Show version
|
||||||
dropshell version
|
dropshell version
|
||||||
|
|
||||||
# Check system status
|
|
||||||
dropshell status
|
|
||||||
|
|
||||||
# List configured servers
|
# List configured servers
|
||||||
dropshell servers
|
dropshell servers
|
||||||
```
|
```
|
||||||
|
@ -20,7 +20,6 @@ void print_help() {
|
|||||||
std::cout << " version Show version information" << std::endl;
|
std::cout << " version Show version information" << std::endl;
|
||||||
std::cout << " init DIR Initialize the user directory for server configurations" << std::endl;
|
std::cout << " init DIR Initialize the user directory for server configurations" << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << " status Check system status" << std::endl;
|
|
||||||
std::cout << " servers List configured servers" << std::endl;
|
std::cout << " servers List configured servers" << std::endl;
|
||||||
std::cout << " servers NAME Show details for specific server" << std::endl;
|
std::cout << " servers NAME Show details for specific server" << std::endl;
|
||||||
std::cout << " templates List available templates" << std::endl;
|
std::cout << " templates List available templates" << std::endl;
|
||||||
@ -36,6 +35,7 @@ void print_help() {
|
|||||||
std::cout << " dropshell templates" << std::endl;
|
std::cout << " dropshell templates" << std::endl;
|
||||||
std::cout << " dropshell install myserver myservice" << std::endl;
|
std::cout << " dropshell install myserver myservice" << std::endl;
|
||||||
std::cout << " dropshell run myserver myservice status" << std::endl;
|
std::cout << " dropshell run myserver myservice status" << std::endl;
|
||||||
|
std::cout << " dropshell backup myserver myservice" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
||||||
@ -67,11 +67,6 @@ int main(int argc, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == "status") {
|
|
||||||
dropshell::check_status();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd == "servers") {
|
if (cmd == "servers") {
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
// Show details for specific server
|
// Show details for specific server
|
||||||
|
@ -118,6 +118,11 @@ std::string server_env::get_variable(const std::string& name) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::map<std::string, std::string> &server_env::get_variables() const
|
||||||
|
{
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
std::string server_env::get_SSH_HOST() {
|
std::string server_env::get_SSH_HOST() {
|
||||||
return get_variable("SSH_HOST");
|
return get_variable("SSH_HOST");
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ class server_env {
|
|||||||
public:
|
public:
|
||||||
server_env(const std::string& path);
|
server_env(const std::string& path);
|
||||||
std::string get_variable(const std::string& name);
|
std::string get_variable(const std::string& name);
|
||||||
|
const std::map<std::string, std::string>& get_variables() const;
|
||||||
|
|
||||||
std::string get_SSH_HOST();
|
std::string get_SSH_HOST();
|
||||||
std::string get_SSH_USER();
|
std::string get_SSH_USER();
|
||||||
|
@ -289,4 +289,28 @@ bool server_service::backup() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool server_service::is_healthy()
|
||||||
|
{
|
||||||
|
if (!m_server_env) {
|
||||||
|
std::cerr << "Error: Server service not initialized" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string service_dir = m_server_env->get_DROPSHELL_DIR() + "/" + m_service_name;
|
||||||
|
std::string script_dir = service_dir + "/template";
|
||||||
|
std::string env_path = service_dir + "/" + m_service_name + ".env";
|
||||||
|
|
||||||
|
std::stringstream ssh_cmd;
|
||||||
|
ssh_cmd << "ssh -p " << m_server_env->get_SSH_PORT() << " "
|
||||||
|
<< m_server_env->get_SSH_USER() << "@" << m_server_env->get_SSH_HOST() << " ";
|
||||||
|
|
||||||
|
// Run status script, does not display output.
|
||||||
|
std::string run_cmd = ssh_cmd.str() + "'cd " + script_dir +
|
||||||
|
" && /bin/bash status.sh " + env_path + " > /dev/null 2>&1'";
|
||||||
|
if (system(run_cmd.c_str()) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -44,6 +44,12 @@ class server_service {
|
|||||||
// 4. copy it to the local user_dir/backups folder
|
// 4. copy it to the local user_dir/backups folder
|
||||||
bool backup();
|
bool backup();
|
||||||
|
|
||||||
|
|
||||||
|
// check health of service. Silent.
|
||||||
|
// 1. run status.sh on the server
|
||||||
|
// 2. return the output of the status.sh script
|
||||||
|
bool is_healthy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_server_name;
|
std::string m_server_name;
|
||||||
std::string m_service_name;
|
std::string m_service_name;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "init_user_directory.hpp"
|
#include "init_user_directory.hpp"
|
||||||
#include "dropshell.hpp"
|
#include "dropshell.hpp"
|
||||||
#include "server_env.hpp"
|
#include "server_env.hpp"
|
||||||
|
#include "server_service.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -94,34 +95,19 @@ void show_server_details(const std::string& server_name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path env_file = server_dir / "_server.env";
|
//---------------------
|
||||||
if (!fs::exists(env_file)) {
|
std::cout << "Server Configuration: " << server_name << std::endl;
|
||||||
std::cerr << "Error: Server configuration file not found" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Server Details: " << server_name << std::endl;
|
|
||||||
std::cout << std::string(40, '-') << std::endl;
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
|
|
||||||
std::ifstream file(env_file.string());
|
server_env env(server_dir.string());
|
||||||
std::string line;
|
|
||||||
while (std::getline(file, line)) {
|
for (const auto& [key, value] : env.get_variables()) {
|
||||||
if (!line.empty() && line[0] != '#') {
|
std::cout << key << ": " << value << std::endl;
|
||||||
std::cout << line << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------
|
||||||
// Check if server is reachable via SSH
|
// Check if server is reachable via SSH
|
||||||
std::string ssh_address;
|
std::string ssh_address = env.get_SSH_HOST();
|
||||||
file.clear();
|
|
||||||
file.seekg(0);
|
|
||||||
while (std::getline(file, line)) {
|
|
||||||
if (boost::starts_with(line, "SSH_ADDRESS=")) {
|
|
||||||
ssh_address = line.substr(12);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ssh_address.empty()) {
|
if (!ssh_address.empty()) {
|
||||||
std::cout << std::endl << "Server Status:" << std::endl;
|
std::cout << std::endl << "Server Status:" << std::endl;
|
||||||
std::cout << std::string(40, '-') << std::endl;
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
@ -142,6 +128,26 @@ void show_server_details(const std::string& server_name) {
|
|||||||
std::cout << "Status: Offline" << std::endl;
|
std::cout << "Status: Offline" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------
|
||||||
|
// list services, and run healthcheck on each
|
||||||
|
std::cout << "Services: " << server_name << std::endl;
|
||||||
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
|
|
||||||
|
std::string green_tick = "\033[32m✓\033[0m";
|
||||||
|
std::string red_cross = "\033[31m✗\033[0m";
|
||||||
|
|
||||||
|
std::vector<std::string> services = get_server_services(server_name);
|
||||||
|
for (const auto& service : services) {
|
||||||
|
bool healthy = false;
|
||||||
|
server_service ss;
|
||||||
|
if (ss.init(server_name, service))
|
||||||
|
if (ss.is_healthy())
|
||||||
|
healthy=true;
|
||||||
|
|
||||||
|
std::cout << service << ": " << (healthy ? green_tick : red_cross) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
Loading…
x
Reference in New Issue
Block a user