mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-08-03 03:09:44 -04:00
✨ feat(casaos-healthcheck): Add Docker port check and improve version display (#11)
This commit introduces the following changes: 1. Adds a new function `check_docker_ports` to the `casaos-healthcheck/run.sh` script. This function checks if Docker is installed and running, and if UFW (Uncomplicated Firewall) is installed and active. It then retrieves all running Docker containers and checks if the ports exposed by these containers are allowed by the UFW rules. If a port is not allowed, a warning is displayed. 2. Updates the version display in the `print_header` function from "BigBearCasaOS Healthcheck V3.0" to "BigBearCasaOS Healthcheck V3.1". The Docker port check is an important addition to the healthcheck script, as it helps identify potential issues with firewall rules that may be blocking Docker container ports. This can be especially useful in troubleshooting network-related problems. The version update reflects the changes introduced in this commit.
This commit is contained in:
@@ -287,6 +287,45 @@ check_system_updates() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_docker_ports() {
|
||||
print_header "Docker Container Port Check"
|
||||
|
||||
# Check if Docker is installed and running
|
||||
if ! command -v docker &> /dev/null || ! docker info &> /dev/null; then
|
||||
print_color "0;33" "${WARNING_MARK} Docker is not installed or not running. Skipping Docker port check."
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if UFW is installed and active
|
||||
if ! command -v ufw &> /dev/null || ! ufw status | grep -q "Status: active"; then
|
||||
print_color "0;33" "${WARNING_MARK} UFW is not installed or not active. Skipping firewall check for Docker ports."
|
||||
return
|
||||
fi
|
||||
|
||||
# Get UFW rules
|
||||
ufw_rules=$(sudo ufw status | grep -E '^[0-9]+' | awk '{print $1}')
|
||||
|
||||
# Get all running Docker containers
|
||||
containers=$(docker ps --format "{{.Names}}")
|
||||
|
||||
for container in $containers; do
|
||||
# Get port mappings for each container
|
||||
ports=$(docker port $container | awk '{print $3}' | cut -d ':' -f2)
|
||||
|
||||
for port in $ports; do
|
||||
if echo "$ufw_rules" | grep -q "^$port$"; then
|
||||
print_color "0;32" "${CHECK_MARK} Port $port for container $container is allowed by UFW."
|
||||
else
|
||||
print_color "0;31" "${CROSS_MARK} Port $port for container $container might be blocked by UFW."
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo
|
||||
print_color "0;33" "Note: Please manually verify UFW rules for more complex configurations."
|
||||
echo " You can do this by running 'sudo ufw status verbose'"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
if [[ "$1" == "simulated_test" ]]; then
|
||||
echo "Running in simulated test mode..."
|
||||
@@ -303,7 +342,7 @@ elif [[ "$1" == "real_test" ]]; then
|
||||
else
|
||||
# Normal script execution
|
||||
# Display Welcome
|
||||
print_header "BigBearCasaOS Healthcheck V3.0"
|
||||
print_header "BigBearCasaOS Healthcheck V3.1"
|
||||
echo "Here are some links:"
|
||||
echo "https://community.bigbeartechworld.com"
|
||||
echo "https://github.com/BigBearTechWorld"
|
||||
@@ -352,6 +391,9 @@ else
|
||||
print_color "0;31" "${CROSS_MARK} Error: Configuration file not found."
|
||||
fi
|
||||
|
||||
# Docker port check
|
||||
check_docker_ports
|
||||
|
||||
# DNS resolution check for Docker registries
|
||||
check_dns_resolution
|
||||
|
||||
|
||||
Reference in New Issue
Block a user