Skip to content

Commit 048e688

Browse files
committed
add linux bash script
1 parent 8775443 commit 048e688

File tree

6 files changed

+288
-133
lines changed

6 files changed

+288
-133
lines changed

BootstrapNodes.sh

-7
This file was deleted.

LinuxStartNodes.sh

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
# Kill any running Go processes
4+
ps aux | grep go | grep -v grep | awk '{print $2}' | xargs kill -9
5+
6+
# Remove previous files and create output directory
7+
rm -f DispersalNode.txt
8+
rm -f bootstrap_addrs.txt
9+
rm -rf output
10+
mkdir output
11+
12+
# Configuration
13+
NUM_NODES=21
14+
PORT_BASE=4007
15+
BOOTSTRAP_PORT_BASE=4001
16+
BOOTSTRAP_NODES=3
17+
BOOTSTRAP_READY_TIMEOUT=30
18+
IP_BASE="127.0.0."
19+
CODING_METHOD="RS"
20+
MODE="download"
21+
22+
# Function to set up IP aliases
23+
setup_ip_aliases() {
24+
for i in $(seq 1 $((BOOTSTRAP_NODES + NUM_NODES + 1))); do
25+
ip_suffix=$((i + 1))
26+
ip="${IP_BASE}${ip_suffix}"
27+
if ! ip addr show lo | grep -q "$ip"; then
28+
sudo ip addr add $ip dev lo
29+
echo "Aliased $ip to loopback interface."
30+
else
31+
echo "$ip is already aliased to loopback interface."
32+
fi
33+
done
34+
sudo ip link set dev lo up
35+
}
36+
37+
# Function to check if a bootstrap node is ready
38+
check_bootstrap_ready() {
39+
local ip=$1
40+
local port=$2
41+
for i in $(seq 1 $BOOTSTRAP_READY_TIMEOUT); do
42+
nc -z $ip $port && return 0
43+
sleep 1
44+
done
45+
return 1
46+
}
47+
48+
# Set up IP aliases
49+
setup_ip_aliases
50+
51+
# Start tmux session
52+
tmux new-session -d -s mynodes -n "BootstrapNode0"
53+
54+
# Start the bootstrap nodes first
55+
for i in $(seq 0 $((BOOTSTRAP_NODES - 1)))
56+
do
57+
ip_suffix=$((i + 1))
58+
ip="${IP_BASE}${ip_suffix}"
59+
if [ $i -eq 0 ]; then
60+
tmux send-keys "go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i)) -bootstrap=true -ip=$ip -mode=$MODE -coding=$CODING_METHOD" C-m
61+
else
62+
tmux new-window -t mynodes: -n "BootstrapNode$i" "go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i)) -bootstrap=true -ip=$ip -mode=$MODE -coding=$CODING_METHOD; read"
63+
fi
64+
done
65+
66+
# Wait for all bootstrap nodes to be ready
67+
for i in $(seq 0 $((BOOTSTRAP_NODES - 1)))
68+
do
69+
ip_suffix=$((i + 1))
70+
ip="${IP_BASE}${ip_suffix}"
71+
port=$((BOOTSTRAP_PORT_BASE + i))
72+
echo "Waiting for BootstrapNode$i on IP $ip and port $port to be ready..."
73+
if ! check_bootstrap_ready $ip $port; then
74+
echo "BootstrapNode$i on IP $ip and port $port did not become ready in time. Exiting..."
75+
exit 1
76+
fi
77+
echo "BootstrapNode$i on IP $ip and port $port is ready."
78+
done
79+
80+
echo "All bootstrap nodes are ready. Starting regular nodes in 10 seconds..."
81+
sleep 10
82+
83+
# Start Node 1 in the current tmux window
84+
tmux new-window -t mynodes: -n "Node1"
85+
tmux send-keys -t mynodes:Node1 "go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -mode=$MODE -coding=$CODING_METHOD" C-m
86+
87+
# Start the rest of the regular nodes in tmux windows
88+
for i in $(seq 2 $((NUM_NODES + 1)))
89+
do
90+
ip_suffix=$((i + 6))
91+
ip="${IP_BASE}${ip_suffix}"
92+
tmux new-window -t mynodes: -n "Node$i" "go run ./cmd/main.go -node=Node$i -port=$((PORT_BASE + i - 2)) -ip=$ip -mode=$MODE -coding=$CODING_METHOD; read"
93+
sleep 2
94+
echo "Node$i started on port $((PORT_BASE + i - 2)) with IP $ip -coding=$CODING_METHOD"
95+
done
96+
97+
echo "$NUM_NODES nodes started in separate tmux windows. Use 'tmux attach -t mynodes' to view them."

StartNodes.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ rm -rf output
99
mkdir output
1010

1111
# Number of regular nodes to start
12-
NUM_NODES=41
12+
NUM_NODES=21
1313
PORT_BASE=4007
1414
BOOTSTRAP_PORT_BASE=4001
15-
BOOTSTRAP_NODES=4
15+
BOOTSTRAP_NODES=3
1616
BOOTSTRAP_READY_TIMEOUT=30
1717
IP_BASE="127.0.0."
1818
CODING_METHOD="RS"
19+
MODE="download"
1920

2021

2122
# Function to set up IP aliases
@@ -51,7 +52,7 @@ for i in $(seq 0 $BOOTSTRAP_NODES)
5152
do
5253
ip_suffix=$((i + 1))
5354
ip="${IP_BASE}${ip_suffix}"
54-
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i - 1)) -bootstrap=true -ip=$ip -coding=$CODING_METHOD\""
55+
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=BootstrapNode$i -port=$((BOOTSTRAP_PORT_BASE + i - 1)) -bootstrap=true -ip=$ip -mode=$MODE -coding=$CODING_METHOD\""
5556
done
5657

5758
# Wait for all bootstrap nodes to be ready
@@ -72,18 +73,18 @@ echo "All bootstrap nodes are ready. Starting regular nodes in 10 seconds..."
7273
sleep 10
7374

7475
echo "Node 1 can be started manually with the following command:"
75-
echo "cd $(pwd) && go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -coding=$CODING_METHOD"
76+
echo "cd $(pwd) && go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -mode=$MODE -coding=$CODING_METHOD"
7677

7778
# Start Node 1 automatically
78-
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -coding=$CODING_METHOD\""
79+
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=Node1 -port=4006 -ip=${IP_BASE}7 -mode=$MODE -coding=$CODING_METHOD\""
7980
sleep 5
8081

8182
# Start the rest of the regular nodes
8283
for i in $(seq 2 $((NUM_NODES + 1)))
8384
do
8485
ip_suffix=$((i + 6))
8586
ip="${IP_BASE}${ip_suffix}"
86-
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=Node$i -port=$((PORT_BASE + i - 2)) -ip=$ip -coding=$CODING_METHOD\""
87+
osascript -e "tell application \"Terminal\" to do script \"cd '$(pwd)' && go run ./cmd/main.go -node=Node$i -port=$((PORT_BASE + i - 2)) -ip=$ip -mode=$MODE -coding=$CODING_METHOD\""
8788
sleep 2
8889
echo "Node$i started on port $((PORT_BASE + i - 2)) with IP $ip -coding=$CODING_METHOD"
8990
done

0 commit comments

Comments
 (0)