@@ -25,8 +25,17 @@ if [ ! -f "$CA_FILE" ]; then
25
25
exit 1
26
26
fi
27
27
28
- # Update MongoDB configuration to use TLS
29
- echo " Updating MongoDB configuration to use TLS..."
28
+ # Check for the replica set name file created by bootstrap.sh
29
+ if [ -f " /tmp/mongodb_replica_set" ]; then
30
+ REPLICA_SET=$( cat /tmp/mongodb_replica_set)
31
+ echo " Found replica set name: $REPLICA_SET "
32
+ else
33
+ echo " ⚠️ WARNING: Replica set name file not found. Using default name 'rs0'."
34
+ REPLICA_SET=" rs0"
35
+ fi
36
+
37
+ # Update MongoDB configuration to use TLS and add replication
38
+ echo " Updating MongoDB configuration to use TLS and add replication..."
30
39
if [ -f " $MONGO_CONF " ]; then
31
40
# Backup the current MongoDB configuration
32
41
BACKUP_FILE=" ${MONGO_CONF} .bak.$( date +%Y%m%d%H%M%S) "
@@ -72,6 +81,15 @@ if [ -f "$MONGO_CONF" ]; then
72
81
sudo sed -i ' /ssl:/,/[a-z]/ d' " $MONGO_CONF "
73
82
fi
74
83
fi
84
+
85
+ # Add or update replication section
86
+ if grep -q " replication:" " $MONGO_CONF " ; then
87
+ echo " Updating existing replication configuration..."
88
+ sudo sed -i ' /replication:/,/[a-z]/ s|replSetName:.*|replSetName: ' " $REPLICA_SET " ' |' " $MONGO_CONF "
89
+ else
90
+ echo " Adding replication configuration..."
91
+ echo -e " \nreplication:\n replSetName: $REPLICA_SET " | sudo tee -a " $MONGO_CONF "
92
+ fi
75
93
else
76
94
echo " ❌ ERROR: MongoDB configuration file not found at $MONGO_CONF "
77
95
exit 1
@@ -147,9 +165,17 @@ echo "Checking if this is a primary or secondary node..."
147
165
IS_PRIMARY=false
148
166
IS_INITIALIZED=false
149
167
168
+ # Check for the replica set name file created by bootstrap.sh
169
+ if [ -f " /tmp/mongodb_replica_set" ]; then
170
+ REPLICA_SET=$( cat /tmp/mongodb_replica_set)
171
+ echo " Found replica set name: $REPLICA_SET "
172
+ else
173
+ echo " ⚠️ WARNING: Replica set name file not found. Using default name 'rs0'."
174
+ REPLICA_SET=" rs0"
175
+ fi
176
+
150
177
# Check for the primary role flag file created by bootstrap.sh
151
178
if [ -f " /tmp/mongodb_primary_role" ]; then
152
- REPLICA_SET=$( cat /tmp/mongodb_primary_role)
153
179
IS_PRIMARY=true
154
180
echo " This node was set up as a primary for replica set: $REPLICA_SET "
155
181
fi
0 commit comments