-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_cluster.sh
executable file
·38 lines (35 loc) · 1.07 KB
/
create_cluster.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
#!/usr/bin/env bash
set -e
# define all the slave nodes here
# just make sure you always have an quorum
# 3,5,7... of nodes including the master node (rabbit1)
rabbits=(rabbit1 rabbit2 rabbit3)
for rabbit in ${rabbits[*]}; do
while :
do
echo "Checking rabbit nodes for connectivity.."
if docker exec -it "$rabbit" rabbitmqctl -q node_health_check;
then
echo "$rabbit is up and ready for the incoming commands..."
if [ "$rabbit" == "rabbit1" ];
then
sleep 2
# setup the HA mode on the rabbit1 (master) node
docker exec -it "$rabbit" rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
break
else
# join the slave nodes to the cluster
docker exec -it "$rabbit" rabbitmqctl stop_app
sleep 1
docker exec -it "$rabbit" rabbitmqctl reset
sleep 1
docker exec -it "$rabbit" rabbitmqctl join_cluster rabbit@rabbit1
sleep 2
docker exec -it "$rabbit" rabbitmqctl start_app
break
fi
else
sleep 1
fi
done
done