#!/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