Spaces:
Runtime error
Runtime error
anuj
commited on
Commit
·
4f4c931
1
Parent(s):
06d0461
batfa
Browse files
start.sh
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
#!/bin/bash
|
2 |
set -e
|
3 |
|
4 |
-
|
5 |
cat > /tmp/mongod.conf << EOF
|
6 |
storage:
|
7 |
dbPath: /data/db
|
@@ -10,29 +10,56 @@ systemLog:
|
|
10 |
path: /var/log/mongodb.log
|
11 |
logAppend: true
|
12 |
net:
|
13 |
-
bindIp:
|
14 |
port: 27017
|
15 |
replication:
|
16 |
replSetName: rs01
|
|
|
|
|
17 |
EOF
|
18 |
|
19 |
-
# Start MongoDB in background
|
|
|
20 |
mongod --config /tmp/mongod.conf &
|
|
|
21 |
|
22 |
-
# Wait for MongoDB to
|
23 |
echo "Waiting for MongoDB to start..."
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Initialize replica set
|
27 |
echo "Initializing replica set..."
|
28 |
-
mongosh --eval 'rs.initiate()' || {
|
29 |
echo "Failed to initialize replica set"
|
30 |
exit 1
|
31 |
}
|
32 |
|
33 |
# Wait for replica set to initialize
|
34 |
-
echo "Waiting for replica set to
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Start Rocket.Chat
|
38 |
echo "Starting Rocket.Chat..."
|
|
|
1 |
#!/bin/bash
|
2 |
set -e
|
3 |
|
4 |
+
echo "Creating MongoDB configuration..."
|
5 |
cat > /tmp/mongod.conf << EOF
|
6 |
storage:
|
7 |
dbPath: /data/db
|
|
|
10 |
path: /var/log/mongodb.log
|
11 |
logAppend: true
|
12 |
net:
|
13 |
+
bindIp: 0.0.0.0
|
14 |
port: 27017
|
15 |
replication:
|
16 |
replSetName: rs01
|
17 |
+
processManagement:
|
18 |
+
fork: false
|
19 |
EOF
|
20 |
|
21 |
+
# Start MongoDB in the background
|
22 |
+
echo "Starting MongoDB..."
|
23 |
mongod --config /tmp/mongod.conf &
|
24 |
+
MONGO_PID=$!
|
25 |
|
26 |
+
# Wait for MongoDB to be ready
|
27 |
echo "Waiting for MongoDB to start..."
|
28 |
+
max_attempts=30
|
29 |
+
attempt=1
|
30 |
+
while ! mongosh --eval "db.version()" >/dev/null 2>&1; do
|
31 |
+
if [ $attempt -gt $max_attempts ]; then
|
32 |
+
echo "MongoDB failed to start after $max_attempts attempts"
|
33 |
+
exit 1
|
34 |
+
fi
|
35 |
+
echo "Attempt $attempt of $max_attempts: MongoDB not ready yet..."
|
36 |
+
sleep 2
|
37 |
+
attempt=$((attempt + 1))
|
38 |
+
done
|
39 |
+
|
40 |
+
echo "MongoDB started successfully"
|
41 |
|
42 |
# Initialize replica set
|
43 |
echo "Initializing replica set..."
|
44 |
+
mongosh --eval 'rs.initiate({_id: "rs01", members: [{_id: 0, host: "localhost:27017"}]})' || {
|
45 |
echo "Failed to initialize replica set"
|
46 |
exit 1
|
47 |
}
|
48 |
|
49 |
# Wait for replica set to initialize
|
50 |
+
echo "Waiting for replica set to be ready..."
|
51 |
+
attempt=1
|
52 |
+
while ! mongosh --eval "rs.status()" | grep -q '"ok" : 1'; do
|
53 |
+
if [ $attempt -gt $max_attempts ]; then
|
54 |
+
echo "Replica set failed to initialize after $max_attempts attempts"
|
55 |
+
exit 1
|
56 |
+
fi
|
57 |
+
echo "Attempt $attempt of $max_attempts: Replica set not ready yet..."
|
58 |
+
sleep 2
|
59 |
+
attempt=$((attempt + 1))
|
60 |
+
done
|
61 |
+
|
62 |
+
echo "Replica set initialized successfully"
|
63 |
|
64 |
# Start Rocket.Chat
|
65 |
echo "Starting Rocket.Chat..."
|