Spaces:
Runtime error
Runtime error
File size: 1,708 Bytes
26488bb 5552216 26488bb 4f4c931 5552216 ef798ec 5552216 ef798ec 4f4c931 5552216 4f4c931 5552216 4f4c931 ef798ec 4f4c931 ef798ec 4f4c931 26488bb 5552216 4f4c931 5552216 4f4c931 26488bb 046867d 5552216 f8454ad 5552216 |
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 65 66 67 68 69 70 |
#!/bin/bash
set -e
echo "Creating MongoDB configuration..."
cat > /tmp/mongod.conf << EOF
storage:
dbPath: /data/db
systemLog:
destination: file
path: /var/log/mongodb.log
logAppend: true
net:
bindIp: 127.0.0.1
port: 27017
replication:
replSetName: rs01
EOF
# Ensure proper permissions
echo "Setting up permissions..."
chown -R mongodb:mongodb /data/db /var/log/mongodb.log
# Start MongoDB
echo "Starting MongoDB..."
mongod --config /tmp/mongod.conf &
# Wait for MongoDB to be ready
echo "Waiting for MongoDB to start..."
max_attempts=30
attempt=1
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..."
mongosh --eval 'rs.initiate({_id: "rs01", members: [{_id: 0, host: "localhost:27017"}]})' || {
echo "Failed to initialize replica set"
exit 1
}
# Wait for replica set to initialize
echo "Waiting for replica set to be ready..."
attempt=1
while ! mongosh --eval "rs.status()" | grep -q '"ok" : 1'; do
if [ $attempt -gt $max_attempts ]; then
echo "Replica set failed to initialize after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt of $max_attempts: Replica set not ready yet..."
sleep 2
attempt=$((attempt + 1))
done
echo "Replica set initialized successfully"
# Start Rocket.Chat
echo "Starting Rocket.Chat..."
cd /opt/Rocket.Chat
exec node main.js |