-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_go_cluster.sh
More file actions
executable file
·65 lines (53 loc) · 1.75 KB
/
run_go_cluster.sh
File metadata and controls
executable file
·65 lines (53 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Configuration
START_PORT=7001
NUM_NODES=${NUM_NODES:-5}
BINARY_PATH="./build/limedb"
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${GREEN}Building LimeDB Go Node...${NC}"
go build -o build/limedb ./cmd/server/main.go
if [ $? -ne 0 ]; then
echo -e "${RED}Build failed!${NC}"
exit 1
fi
# Set the first node as the seed peer for all others
SEED_PEER="http://localhost:${START_PORT}"
echo -e "${GREEN}Starting ${NUM_NODES} nodes...${NC}"
echo -e "Seed peer: ${SEED_PEER}"
# Array to keep track of PIDs
PIDS=()
# Function to kill all nodes on script exit
cleanup() {
echo -e "\n${RED}Stopping all nodes...${NC}"
for pid in "${PIDS[@]}"; do
kill $pid 2>/dev/null
done
wait
echo -e "${GREEN}Cluster stopped.${NC}"
}
# Trap SIGINT (Ctrl+C) and SIGTERM
trap cleanup SIGINT SIGTERM
# Start Nodes
for ((i=0; i<NUM_NODES; i++)); do
PORT=$((START_PORT + i))
NODE_URL="http://localhost:${PORT}"
if [ $i -eq 0 ]; then
# First node starts without peers (seed node)
echo "Starting Seed Node at ${NODE_URL}..."
$BINARY_PATH -server.port $PORT -node.url "$NODE_URL" -node.routing.virtual-nodes 1 -otel.endpoint "" &
else
# Each node connects to the previous node
PREV_PORT=$((START_PORT + i - 1))
PREV_PEER="http://localhost:${PREV_PORT}"
echo "Starting Node at ${NODE_URL} with peer ${PREV_PEER}..."
$BINARY_PATH -server.port $PORT -node.url "$NODE_URL" -node.peers "$PREV_PEER" -node.routing.virtual-nodes 1 -otel.endpoint "" &
fi
PIDS+=($!)
done
echo -e "${GREEN}Cluster is running! Press Ctrl+C to stop.${NC}"
echo -e "Try: curl http://localhost:${START_PORT}/api/v1/cluster/state"
# Wait for all background processes
wait