From faaad8d221c3a0c199cef3e5422abc30b6e10f74 Mon Sep 17 00:00:00 2001 From: Nghi Nguyen <70782465+nghi01@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:14:24 -0500 Subject: [PATCH] Create a script that spins up multiple nodes listening for requests on different ports (#8) * Make spindown script * Iterate through the ports and create a port address list * Finish the spin down script * Final cleanup with SIGTERM * Finish account for bound ports * Finish implementing spin down script spinning down based on port_list.txt --------- Co-authored-by: Nghi Nguyen --- .gitignore | 2 ++ devops/deploy/spin-down-script.sh | 19 +++++++++++++++++++ devops/deploy/spin-up-script.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100755 devops/deploy/spin-down-script.sh create mode 100755 devops/deploy/spin-up-script.sh diff --git a/.gitignore b/.gitignore index 28614df..6c73ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,5 @@ ENV/ # Rope project settings .ropeproject +# Spin up script +devops/deploy/port_list.txt diff --git a/devops/deploy/spin-down-script.sh b/devops/deploy/spin-down-script.sh new file mode 100755 index 0000000..842529a --- /dev/null +++ b/devops/deploy/spin-down-script.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Now fully implemented spinning down through the port_list.txt +IP=127.0.0.1 +declare -a PORTS=() +while IFS= read -r line +do + PORTS+=("$line") +done < "port_list.txt" + +# Iterate through the list, killing each controlling process while looping +for port in ${PORTS[*]} +do + echo "Killing processes at $IP:$port" + temp=$IP:$port + kill -15 $(netstat -anp | grep $temp | awk '{print $6}' | awk -F/ '{print $1}') +done + +echo -n > "port_list.txt" diff --git a/devops/deploy/spin-up-script.sh b/devops/deploy/spin-up-script.sh new file mode 100755 index 0000000..a6d2a63 --- /dev/null +++ b/devops/deploy/spin-up-script.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +PSTART=${1:-50000} +PEND=${2:-50050} +# Just a basic script to spin up listening servers on different ports in dynamic port range +IP=127.0.0.1 +COUNT=0 +((NUM_PORTS=${PEND}-${PSTART})) + +echo "Total number of ports: $NUM_PORTS" +export PYTHONPATH=../../src/main/py + +port=$PSTART + +while [ ${COUNT} -lt ${NUM_PORTS} ] +do + #Check for Open ports, if open then OK, else continue + if ! netstat -apn | grep -q "$IP:$port" + then + echo "Starting on port $port" + python3 -m sample_module.udp_server ${port} & + echo "$port" >> port_list.txt + ((port++)) + ((COUNT++)) + else + echo "Port $port already bound" + ((port++)) + fi +done