mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-11 23:47:32 +08:00
- Replace complex inline bash script with dedicated init script - Use MongoDB built-in /docker-entrypoint-initdb.d/ mechanism - Create scripts/mongo-init.sh for user creation - Improve readability and maintainability Fixes #3632
21 lines
594 B
Bash
21 lines
594 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "Creating OpenIM user in database ${MONGO_INITDB_DATABASE}..."
|
|
|
|
mongosh -u "${MONGO_INITDB_ROOT_USERNAME}" -p "${MONGO_INITDB_ROOT_PASSWORD}" --authenticationDatabase admin <<EOF
|
|
use ${MONGO_INITDB_DATABASE}
|
|
if (!db.getUser("${MONGO_OPENIM_USERNAME}")) {
|
|
db.createUser({
|
|
user: "${MONGO_OPENIM_USERNAME}",
|
|
pwd: "${MONGO_OPENIM_PASSWORD}",
|
|
roles: [{role: "readWrite", db: "${MONGO_INITDB_DATABASE}"}]
|
|
})
|
|
print("OpenIM user created successfully")
|
|
} else {
|
|
print("User ${MONGO_OPENIM_USERNAME} already exists")
|
|
}
|
|
EOF
|
|
|
|
echo "OpenIM user setup completed"
|