Skip to content

Commit

Permalink
most de
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel N committed Mar 11, 2024
1 parent 1985b3e commit 9adcc0d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions couchdb/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ setUuid() {
COUCHDB_UUID=$(cat /proc/sys/kernel/random/uuid)
fi
# Set uuid only if not already present
if [ -z $(grep -Pzor "\[couchdb\]\nuuid =" $CLUSTER_CREDENTIALS) ]; then
if grep -Pzq "\[couchdb\]\nuuid =" $CLUSTER_CREDENTIALS; then
printf "\n[couchdb]\nuuid = %s\n" "$COUCHDB_UUID" >> $CLUSTER_CREDENTIALS
fi
}
Expand Down Expand Up @@ -106,23 +106,23 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
setUuid
fi

if [ "$COUCHDB_SYNC_ADMINS_NODE" ]; then
# Wait until couchdb1 node is ready and then retrieve salted password. We need to use same
# hashed password across all nodes so that session cookies can be reused.
/bin/bash /opt/couchdb/etc/set-up-cluster.sh check_if_couchdb_is_ready http://$COUCHDB_USER:$COUCHDB_PASSWORD@$COUCHDB_SYNC_ADMINS_NODE:5984
COUCHDB_HASHED_PASSWORD=`curl http://$COUCHDB_USER:$COUCHDB_PASSWORD@$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/admins/$COUCHDB_USER | sed "s/^\([\"]\)\(.*\)\1\$/\2/g"`

if ! grep -Pzoqr "$COUCHDB_USER = $COUCHDB_HASHED_PASSWORD" $CLUSTER_CREDENTIALS; then
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_HASHED_PASSWORD" >> $CLUSTER_CREDENTIALS
fi
if [ "$COUCHDB_SYNC_ADMINS_NODE" ]; then
# Wait until couchdb1 node is ready and then retrieve salted password. We need to use same
# hashed password across all nodes so that session cookies can be reused.
/bin/bash /opt/couchdb/etc/set-up-cluster.sh check_if_couchdb_is_ready "http://$COUCHDB_SYNC_ADMINS_NODE:5984"
COUCHDB_HASHED_PASSWORD=$(curl -u "$COUCHDB_USER:$COUCHDB_PASSWORD" "http://$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/admins/$COUCHDB_USER" | sed "s/^\([\"]\)\(.*\)\1\$/\2/g")

COUCHDB_SECRET=`curl http://$COUCHDB_USER:$COUCHDB_PASSWORD@$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/couch_httpd_auth/secret | sed "s/^\([\"]\)\(.*\)\1\$/\2/g"`
setSecret
if ! grep -Pzq "$COUCHDB_USER = $COUCHDB_HASHED_PASSWORD" $CLUSTER_CREDENTIALS; then
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_HASHED_PASSWORD" >>$CLUSTER_CREDENTIALS
fi

COUCHDB_UUID=`curl http://$COUCHDB_USER:$COUCHDB_PASSWORD@$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/couchdb/uuid | sed "s/^\([\"]\)\(.*\)\1\$/\2/g"`
setUuid
fi
COUCHDB_SECRET=$(curl -u "$COUCHDB_USER:$COUCHDB_PASSWORD" "http://$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/couch_httpd_auth/secret" | sed "s/^\([\"]\)\(.*\)\$/\2/g")
setSecret

COUCHDB_UUID=$(curl -u "$COUCHDB_USER:$COUCHDB_PASSWORD" "http://$COUCHDB_SYNC_ADMINS_NODE:5984/_node/couchdb@$COUCHDB_SYNC_ADMINS_NODE/_config/couchdb/uuid" | sed "s/^\([\"]\)\(.*\)\$/\2/g")
setUuid
fi

#Start clustering after UUID, Secret and Nodename are written.
/bin/bash /opt/couchdb/etc/set-up-cluster.sh
Expand Down

0 comments on commit 9adcc0d

Please sign in to comment.