pull/2196/head
skiffer-git 7 months ago
parent 843a704c6f
commit 802052d37f

@ -1,4 +1,3 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved. # Copyright © 2023 OpenIM. All rights reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -12,34 +11,32 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Wait for Kafka to be ready mongosh <<EOF
KAFKA_SERVER=localhost:9092 use admin
MAX_ATTEMPTS=300 var rootUsername = '$MONGO_INITDB_ROOT_USERNAME';
attempt_num=1 var rootPassword = '$MONGO_INITDB_ROOT_PASSWORD';
echo "Waiting for Kafka to be ready..." var authResult = db.auth(rootUsername, rootPassword);
until /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server $KAFKA_SERVER; do if (authResult) {
echo "Attempt $attempt_num of $MAX_ATTEMPTS: Kafka not ready yet..." print('Authentication successful for root user: ' + rootUsername);
if [ $attempt_num -eq $MAX_ATTEMPTS ]; then } else {
echo "Kafka not ready after $MAX_ATTEMPTS attempts, exiting" print('Authentication failed for root user: ' + rootUsername + ' with password: ' + rootPassword);
exit 1 quit(1);
fi }
attempt_num=$((attempt_num+1)) var dbName = '$MONGO_INITDB_DATABASE';
sleep 1 db = db.getSiblingDB(dbName);
done var openimUsername = '$MONGO_OPENIM_USERNAME';
echo "Kafka is ready. Creating topics..." var openimPassword = '$MONGO_OPENIM_PASSWORD';
topics=("toRedis" "toMongo" "toPush") var createUserResult = db.createUser({
partitions=8 user: openimUsername,
replicationFactor=1 pwd: openimPassword,
for topic in "${topics[@]}"; do roles: [
if /opt/bitnami/kafka/bin/kafka-topics.sh --create \ { role: 'readWrite', db: dbName }
--bootstrap-server $KAFKA_SERVER \ ]
--replication-factor $replicationFactor \ });
--partitions $partitions \ if (createUserResult.ok == 1) {
--topic $topic print('User creation successful. User: ' + openimUsername + ', Database: ' + dbName);
then } else {
echo "Topic $topic created." print('User creation failed for user: ' + openimUsername + ' in database: ' + dbName);
else quit(1);
echo "Failed to create topic $topic." }
fi EOF
done
echo "All topics created."

Loading…
Cancel
Save