forked from herlesupreeth/docker_open5gs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-sync.sh
More file actions
executable file
·64 lines (50 loc) · 1.28 KB
/
start-sync.sh
File metadata and controls
executable file
·64 lines (50 loc) · 1.28 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
#!/usr/bin/env bash
set -euo pipefail
# --- get env ---
set -a
source .env
set +a
# --- helpers ---
wait_mongo() {
local host="$1"
local port="${2:-27017}"
echo "Waiting for Mongo on ${host}:${port} ..."
until nc -z "$host" "$port" >/dev/null 2>&1; do
sleep 1
done
}
# --- config ---
HOSTS=(${NODE1_IP} ${NODE2_IP} ${NODE3_IP})
############################################################
############################################################
############################################################
docker compose -f 5g-failover.yaml up -d
echo "Waiting until all Mongo instances respond ..."
for host in "${HOSTS[@]}"; do
wait_mongo "$host"
done
echo "All MongoDB instances are ready."
if [[ "$THIS_IP" == "$MONGO_RS_PRIMARY" ]]; then
echo "Attempting to initialize the replica set ..."
mongosh --host ${MONGO_RS_PRIMARY}:27017 <<EOF
try {
rs.status();
print('Replica set already initialized.');
} catch (e) {
printjson(rs.initiate({
_id: '${MONGO_RS_NAME}',
members: [
{ _id: 0, host: '${NODE1_IP}:27017'},
{ _id: 1, host: '${NODE2_IP}:27017'},
{ _id: 2, host: '${NODE3_IP}:27017'}
]
}));
}
EOF
sleep 15
else
echo "Waiting for init and primary election ..."
sleep 20
fi
echo "Replica set status:"
mongosh --eval 'rs.status()'