Tidying
This commit is contained in:
parent
2e652be9f9
commit
b53e0f6654
@ -7,7 +7,7 @@ _dropshell_completions() {
|
|||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
# List of main commands
|
# List of main commands
|
||||||
opts="help version status servers templates autocomplete_list_servers autocomplete_list_services autocomplete_list_commands install backup"
|
opts="help version servers templates autocomplete_list_servers autocomplete_list_services autocomplete_list_commands install backup"
|
||||||
|
|
||||||
# add all commands to opts
|
# add all commands to opts
|
||||||
local commands=($(dropshell autocomplete_list_commands))
|
local commands=($(dropshell autocomplete_list_commands))
|
||||||
|
@ -322,4 +322,73 @@ std::string server_service::healthtick()
|
|||||||
return red_cross;
|
return red_cross;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> server_service::get_ports()
|
||||||
|
{
|
||||||
|
std::vector<int> ports;
|
||||||
|
if (!m_server_env) {
|
||||||
|
std::cerr << "Error: Server service not initialized" << std::endl;
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ssh_cmd = construct_ssh_cmd();
|
||||||
|
std::string script_dir = get_script_dir();
|
||||||
|
std::string script_path = script_dir + "/_ports.sh";
|
||||||
|
|
||||||
|
// Check if service directory exists
|
||||||
|
if (!check_service_dir_exists(ssh_cmd)) {
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if ports script exists
|
||||||
|
if (!check_remote_file_exists(ssh_cmd, script_path)) {
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the ports script and capture output
|
||||||
|
std::string run_cmd = "'cd " + script_dir +
|
||||||
|
" && /bin/bash " + script_path + " " + get_env_path() + "'";
|
||||||
|
|
||||||
|
// Create a temporary file to store the output
|
||||||
|
std::string temp_file = "/tmp/dropshell_ports_" + std::to_string(getpid());
|
||||||
|
std::string full_cmd = ssh_cmd + run_cmd + " > " + temp_file;
|
||||||
|
|
||||||
|
if (!execute_local_command(full_cmd, "Failed to run ports script")) {
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the output file
|
||||||
|
std::ifstream in(temp_file);
|
||||||
|
if (!in.is_open()) {
|
||||||
|
std::cerr << "Error: Failed to read ports output" << std::endl;
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the entire file content
|
||||||
|
std::string content((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
|
// Clean up temporary file
|
||||||
|
std::remove(temp_file.c_str());
|
||||||
|
|
||||||
|
// Process the content
|
||||||
|
std::stringstream ss(content);
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
// First split by commas
|
||||||
|
while (std::getline(ss, token, ',')) {
|
||||||
|
// Then split each comma-separated part by whitespace
|
||||||
|
std::stringstream token_ss(token);
|
||||||
|
std::string port_str;
|
||||||
|
while (token_ss >> port_str) { // This handles all whitespace including newlines
|
||||||
|
try {
|
||||||
|
int port = std::stoi(port_str);
|
||||||
|
ports.push_back(port);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "Warning: Invalid port number: " << port_str << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -50,6 +50,11 @@ 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();
|
||||||
|
|
||||||
|
// get the ports of the service
|
||||||
|
// 1. run _ports.sh on the server
|
||||||
|
// 2. return the output of the _ports.sh script, handling a port per line or comma separated.
|
||||||
|
std::vector<int> get_ports();
|
||||||
|
|
||||||
std::string healthtick();
|
std::string healthtick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -131,6 +131,7 @@ void show_server_details(const std::string& server_name) {
|
|||||||
|
|
||||||
//---------------------
|
//---------------------
|
||||||
// list services, and run healthcheck on each
|
// list services, and run healthcheck on each
|
||||||
|
std::cout << std::endl;
|
||||||
std::cout << "Services: " << server_name << std::endl;
|
std::cout << "Services: " << server_name << std::endl;
|
||||||
std::cout << std::string(40, '-') << std::endl;
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
|
|
||||||
@ -140,13 +141,26 @@ void show_server_details(const std::string& server_name) {
|
|||||||
std::vector<std::string> services = get_server_services(server_name);
|
std::vector<std::string> services = get_server_services(server_name);
|
||||||
for (const auto& service : services) {
|
for (const auto& service : services) {
|
||||||
bool healthy = false;
|
bool healthy = false;
|
||||||
|
std::vector<int> ports;
|
||||||
server_service ss;
|
server_service ss;
|
||||||
if (ss.init(server_name, service))
|
if (ss.init(server_name, service))
|
||||||
|
{
|
||||||
if (ss.is_healthy())
|
if (ss.is_healthy())
|
||||||
healthy=true;
|
healthy=true;
|
||||||
|
ports = ss.get_ports();
|
||||||
std::cout << service << ": " << (healthy ? green_tick : red_cross) << std::endl;
|
}
|
||||||
}
|
std::cout << " " << (healthy ? green_tick : red_cross) << " " << service << ", ports: ";
|
||||||
|
std::cout << "(";
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& port : ports) {
|
||||||
|
if (!first) {
|
||||||
|
std::cout << ", ";
|
||||||
|
}
|
||||||
|
std::cout << port;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
std::cout << ")" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
templates/squashkiwi/_ports.sh
Normal file
5
templates/squashkiwi/_ports.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
source "$(dirname "$0")/_common.sh"
|
||||||
|
load_env "$1" || die "Failed to load environment variables"
|
||||||
|
|
||||||
|
echo $HOST_PORT
|
@ -13,3 +13,10 @@ DOCKER_RUN_CMD="docker run -d \
|
|||||||
if ! create_and_start_container "$DOCKER_RUN_CMD"; then
|
if ! create_and_start_container "$DOCKER_RUN_CMD"; then
|
||||||
die "Failed to start container ${CONTAINER_NAME}"
|
die "Failed to start container ${CONTAINER_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if the container is running
|
||||||
|
if ! _is_container_running "$CONTAINER_NAME"; then
|
||||||
|
die "Container ${CONTAINER_NAME} is not running"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Container ${CONTAINER_NAME} started"
|
||||||
|
@ -3,3 +3,5 @@ source "$(dirname "$0")/_common.sh"
|
|||||||
load_env "$1" || die "Failed to load environment variables"
|
load_env "$1" || die "Failed to load environment variables"
|
||||||
|
|
||||||
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
||||||
|
|
||||||
|
echo "Container ${CONTAINER_NAME} stopped"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user