Skip to content

Commit

Permalink
Create a script that spins up multiple nodes listening for requests o…
Browse files Browse the repository at this point in the history
…n 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 <quangnghiams@gmail.com>
  • Loading branch information
nghi01 and Nghi Nguyen authored Jan 18, 2024
1 parent afd898f commit faaad8d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ ENV/
# Rope project settings
.ropeproject

# Spin up script
devops/deploy/port_list.txt
19 changes: 19 additions & 0 deletions devops/deploy/spin-down-script.sh
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions devops/deploy/spin-up-script.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit faaad8d

Please sign in to comment.