.
This commit is contained in:
@ -50,6 +50,26 @@ std::vector<ServerInfo> get_configured_servers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
ServerInfo get_server_info(const std::string &server_name)
|
||||
{
|
||||
std::vector<std::string> local_config_directories = gConfig().get_local_config_directories();
|
||||
if (local_config_directories.empty())
|
||||
return ServerInfo();
|
||||
|
||||
for (auto &config_dir : local_config_directories) {
|
||||
std::string server_dir = config_dir + "/" + server_name;
|
||||
if (std::filesystem::exists(server_dir)) {
|
||||
server_env_manager env(server_name);
|
||||
if (!env.is_valid()) {
|
||||
std::cerr << "Error: Invalid server environment file: " << server_dir << std::endl;
|
||||
continue;
|
||||
}
|
||||
return ServerInfo({server_name, env.get_SSH_HOST(), env.get_SSH_USER(), env.get_SSH_PORT()});
|
||||
}
|
||||
}
|
||||
return ServerInfo();
|
||||
}
|
||||
|
||||
// https://github.com/bloomen/transwarp?tab=readme-ov-file#range-functions
|
||||
void list_servers() {
|
||||
auto servers = get_configured_servers();
|
||||
|
@ -17,6 +17,10 @@ namespace dropshell {
|
||||
};
|
||||
|
||||
std::vector<ServerInfo> get_configured_servers();
|
||||
|
||||
ServerInfo get_server_info(const std::string& server_name);
|
||||
|
||||
|
||||
void list_servers();
|
||||
void show_server_details(const std::string& server_name);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "config.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "server_env_manager.hpp"
|
||||
#include "servers.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
@ -209,6 +211,11 @@ void get_all_service_env_vars(const std::string &server_name, const std::string
|
||||
all_env_vars["SERVER"] = server_name;
|
||||
all_env_vars["SERVICE"] = service_name;
|
||||
|
||||
ServerInfo server_info = get_server_info(server_name);
|
||||
if (server_info.ssh_host.empty())
|
||||
std::cerr << "Error: Server " << server_name << " not found - ssh_host empty, so HOST_NAME not set" << std::endl;
|
||||
all_env_vars["HOST_NAME"] = server_info.ssh_host;
|
||||
|
||||
// Lambda function to load environment variables from a file
|
||||
auto load_env_file = [&all_env_vars](const std::string& file) {
|
||||
if (!file.empty() && std::filesystem::exists(file)) {
|
||||
|
Reference in New Issue
Block a user