Server Seas Arrr! In the vast seas o' server management, yer mission be to set up a load…
- User
Server Seas Arrr! In the vast seas o' server management, yer mission be to set up a load balancer on port 11000. This balancer'll divvy up incoming requests 'twixt three identical servers, sailin' on ports 11001, 11002 and 11003. Show yer mettle in the art o' load balancin' by configurin' this crew with precision, keepin' the ship runnin' smooth and fair for all who come aboard. Constraints The script must be purely written in bash within the execute.sh file. Output / Evaluation Criteria HTTP requests to the load balancer must be distributed evenly between the given servers.
The script should only execute if the three servers are running on the specified ports.
- Assistant
#!/bin/bash # Function to check if a port is open is_port_open() { nc -z localhost "$1" &> /dev/null } # Check if the servers are running on ports 11001, 11002, 11003 for port in 11001 11002 11003; do if ! is_port_open "$port"; then echo "Backend server on port $port is not running." exit 1 fi done # Set up the initial counter echo 0 > /tmp/backend_counter # Start the load balancer socat TCP-LISTEN:11000,reuseaddr,fork EXEC:"bash -c './handle_connection.sh'"Create a file named
handle_connection.shin the same directory with the following content: