Last active
November 15, 2016 20:55
-
-
Save aclemmensen/a2fe34688387ebd36856cb6a6e9ab2b6 to your computer and use it in GitHub Desktop.
Script to start a Couchbase node as either master or worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Taken from here: | |
# https://github.com/arun-gupta/docker-images/blob/master/couchbase/configure-node.sh | |
set -x | |
set -m | |
set -o pipefail | |
/entrypoint.sh couchbase-server & | |
sleep 15 | |
# Setup index and memory quota | |
curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=${MEMORY_QUOTA:-300} -d indexMemoryQuota=${INDEX_MEMORY_QUOTA:-300} | |
# Setup services | |
curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Cn1ql%2Cindex | |
# Setup credentials | |
curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password | |
# Setup Memory Optimized Indexes | |
curl -i -u Administrator:password -X POST http://127.0.0.1:8091/settings/indexes -d 'storageMode=memory_optimized' | |
# Load travel-sample bucket | |
#curl -v -u Administrator:password -X POST http://127.0.0.1:8091/sampleBuckets/install -d '["travel-sample"]' | |
echo "Type: $TYPE" | |
if [ "$TYPE" = "WORKER" ]; then | |
sleep 15 | |
echo "Auto Rebalance: $AUTO_REBALANCE" | |
#IP=`hostname -s` | |
#IP=`hostname -I | cut -d ' ' -f1` | |
while true; do | |
HOSTS=$(getent hosts $APP_NAME | awk '{print $1}') | |
if [ $? -eq 0 ]; then | |
echo "Resolved following hosts:\n$HOSTS" | |
echo "$HOSTS" | while read h; do | |
if [ $h == $HOST ]; then | |
echo "Skipping self, $h" | |
else | |
echo "Adding $h to cluster" | |
if [ "$AUTO_REBALANCE" = "true" ]; then | |
couchbase-cli rebalance --cluster=$h:8091 --user=Administrator --password=password --server-add=$HOST --server-add-username=Administrator --server-add-password=password | |
else | |
couchbase-cli server-add --cluster=$h:8091 --user=Administrator --password=password --server-add=$HOST --server-add-username=Administrator --server-add-password=password | |
fi; | |
fi; | |
done | |
break; | |
else | |
echo "Error resolving, trying again in 10 seconds" | |
sleep 10 | |
fi; | |
done; | |
fi; | |
fg 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment