-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-setup.sh
executable file
·70 lines (59 loc) · 1.63 KB
/
cluster-setup.sh
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
66
67
68
69
70
#!/usr/bin/env bash
set -e
echo "Setting up cluster environment..."
if [ -z "$SKIP_SYSCTL" ]; then
echo "Attempting system settings..."
sysctl vm.overcommit_memory=1 2>/dev/null || true
else
echo "Skipping system settings (handled by Docker)"
fi
echo "Cleaning up data directories..."
rm -rf /data/*
# Initialize nodes
init_nodes() {
for port in $(seq 6379 6381); do
mkdir -p /data/${port}
cat > /data/${port}/valkey.conf <<EOF
port ${port}
cluster-enabled yes
cluster-config-file /data/${port}/nodes.conf
cluster-node-timeout 30000
appendonly yes
dir /data/${port}
bind 0.0.0.0
protected-mode no
cluster-announce-ip 127.0.0.1
daemonize yes
EOF
valkey-server /data/${port}/valkey.conf
until valkey-cli -p ${port} ping 2>/dev/null; do
echo "Waiting for node ${port} to start..."
sleep 1
done
done
}
echo "Initializing nodes..."
init_nodes
echo "Waiting for nodes to stabilize..."
sleep 5
echo "Initializing cluster..."
yes "yes" | valkey-cli --cluster create \
127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 \
--cluster-replicas 0
# Wait for cluster to stabilize
echo "Waiting for cluster to stabilize..."
for i in {1..30}; do
if valkey-cli -p 6379 cluster info | grep -q "cluster_state:ok"; then
echo "Cluster is stable"
break
fi
echo "Waiting for cluster to stabilize (attempt $i)..."
sleep 2
done
echo "Cluster initialization complete"
# Keep container running and monitor cluster
while true; do
echo "Cluster Status at $(date):"
valkey-cli -p 6379 cluster info || echo "Failed to get cluster info"
sleep 60
done