@@ -58,32 +58,54 @@ CONNECTION_DOMAIN="$DOMAIN"
58
58
# Try to connect using the domain name first (if not localhost)
59
59
if [ " $DOMAIN " != " localhost" ]; then
60
60
echo " Attempting to connect to MongoDB using domain name: $DOMAIN "
61
- if mongosh --host $DOMAIN --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> /dev/null; then
61
+ echo " Running command: mongosh --host $DOMAIN --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p [PASSWORD] --authenticationDatabase admin --quiet --eval \" JSON.stringify(rs.status())\" "
62
+
63
+ # Create a temporary file to capture errors
64
+ ERROR_LOG=$( mktemp)
65
+ if mongosh --host $DOMAIN --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> $ERROR_LOG ; then
62
66
echo " ✅ Successfully connected to MongoDB using domain name: $DOMAIN "
63
67
else
64
- echo " Connection using domain name failed. Trying localhost..."
68
+ echo " Connection using domain name failed. Error output:"
69
+ cat $ERROR_LOG
70
+ rm -f $ERROR_LOG
71
+
72
+ echo " Trying localhost instead..."
73
+ echo " Running command: mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p [PASSWORD] --authenticationDatabase admin --quiet --eval \" JSON.stringify(rs.status())\" "
74
+
65
75
# If that fails, try connecting using localhost
66
- if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> /dev/null; then
76
+ if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> $ERROR_LOG ; then
77
+ echo " ✅ Successfully connected to MongoDB using localhost."
78
+ # Note: We're not changing CONNECTION_DOMAIN, only the DOMAIN for the current connection
79
+ DOMAIN=" localhost"
80
+ else
81
+ echo " ❌ ERROR: Failed to connect to MongoDB using both domain name and localhost."
82
+ echo " Error output from localhost attempt:"
83
+ cat $ERROR_LOG
84
+ rm -f $ERROR_LOG
85
+ rm -f $TEMP_FILE
86
+ exit 1
87
+ fi
88
+ fi
89
+ rm -f $ERROR_LOG
90
+ else
91
+ # Just try localhost
92
+ echo " Attempting to connect to MongoDB using localhost"
93
+ echo " Running command: mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p [PASSWORD] --authenticationDatabase admin --quiet --eval \" JSON.stringify(rs.status())\" "
94
+
95
+ # Create a temporary file to capture errors
96
+ ERROR_LOG=$( mktemp)
97
+ if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> $ERROR_LOG ; then
67
98
echo " ✅ Successfully connected to MongoDB using localhost."
68
- # Note: We're not changing CONNECTION_DOMAIN, only the DOMAIN for the current connection
69
- DOMAIN=" localhost"
70
99
else
71
- echo " ❌ ERROR: Failed to connect to MongoDB using both domain name and localhost."
72
- rm $TEMP_FILE
100
+ echo " ❌ ERROR: Failed to connect to MongoDB using localhost."
101
+ echo " Error output:"
102
+ cat $ERROR_LOG
103
+ rm -f $ERROR_LOG
104
+ rm -f $TEMP_FILE
73
105
exit 1
74
106
fi
107
+ rm -f $ERROR_LOG
75
108
fi
76
- else
77
- # Just try localhost
78
- echo " Attempting to connect to MongoDB using localhost"
79
- if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval " JSON.stringify(rs.status())" > $TEMP_FILE 2> /dev/null; then
80
- echo " ✅ Successfully connected to MongoDB using localhost."
81
- else
82
- echo " ❌ ERROR: Failed to connect to MongoDB using localhost."
83
- rm $TEMP_FILE
84
- exit 1
85
- fi
86
- fi
87
109
88
110
# Check if the command was successful
89
111
if [ $? -ne 0 ] || [ ! -s $TEMP_FILE ]; then
0 commit comments