Spaces:
Sleeping
Sleeping
set -x -e | |
echo "Creating data directory..." | |
mkdir -p /data/db | |
echo "Cleaning up any stale lock files..." | |
rm -f /data/db/mongod.lock | |
echo "Ensuring no MongoDB process is running..." | |
pkill mongod || true # 'true' ensures script continues if no process found | |
echo "Starting MongoDB..." | |
mongod --config /etc/mongod.conf & | |
# Wait for MongoDB to be ready | |
echo "Waiting for MongoDB to start..." | |
max_attempts=30 | |
attempt=1 | |
echo $(ls -l /data/) | |
while ! mongosh --quiet --eval "db.version()" > /dev/null 2>&1; do | |
if [ $attempt -gt $max_attempts ]; then | |
echo "MongoDB failed to start. Showing logs:" | |
cat /var/log/mongodb.log | |
exit 1 | |
fi | |
echo "Attempt $attempt of $max_attempts: MongoDB not ready yet..." | |
sleep 2 | |
attempt=$((attempt + 1)) | |
done | |
echo "MongoDB started successfully" | |
# Initialize replica set | |
echo "Initializing replica set..." | |
if ! mongosh --eval 'rs.status()' --quiet | grep -q 'ok: 1'; then | |
echo "Initializing replica set..." | |
mongosh --eval 'rs.initiate({_id: "rs01", members: [{_id: 0, host: "localhost:27017"}]})' || { | |
echo "Failed to initialize replica set" | |
} | |
else | |
echo "Replica set already initialized" | |
fi | |
echo "Waiting for replica set to initialize..." | |
sleep 5 | |
# Start Rocket.Chat | |
echo "Starting Rocket.Chat..." | |
cd /opt/Rocket.Chat | |
exec node main.js |