blob: 81ed619c6f4bdb8f78af0fa9ee9fa5322a2a961c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/usr/bin/env bash
if [ ! -f /data/db/user_exist ]
then
# Another port to prevent 'address already in use'
/usr/bin/mongod --port 27015 --nounixsocket &
sleep 1
cp /init-mongodb.js /data/db/init-mongodb.js
sed -i "s/REPLACE_USERNAME/$MONGODB_USERNAME/g" /data/db/init-mongodb.js
sed -i "s/REPLACE_PASSWORD/$MONGODB_PASSWORD/g" /data/db/init-mongodb.js
sed -i "s/REPLACE_COLLECTION/$MONGODB_COLLECTION/g" /data/db/init-mongodb.js
# Update and shutdown our DB with changes
/usr/bin/mongosh --eval 'disableTelemetry()' localhost:27015/production /data/db/init-mongodb.js
# /usr/bin/mongosh localhost:27015/production /data/db/init-mongodb.js
sleep 1 # Allow DB to shutdown
/usr/bin/touch /data/db/user_exist
rm /data/db/init-mongodb.js
fi
# Startup normally now with our user
exec /usr/bin/mongod --nounixsocket --bind_ip_all --auth
|