generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcouchbase-init.sh
executable file
·50 lines (41 loc) · 1.83 KB
/
couchbase-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Wait for Couchbase Server to start
until curl -s -u admin:password http://couchbase:8091/pools >/dev/null; do
echo "Waiting for Couchbase to start..."
sleep 5
done
echo "Couchbase is up and running."
if [ ! -e "/home/couchbase_initialized" ] ; then
echo "Initializing the cluster..."
couchbase-cli cluster-init --cluster "couchbase://couchbase" --cluster-name "couchbase" \
--cluster-username "admin" --cluster-password "password" --services "data,index,query" \
--cluster-ramsize 500 --cluster-index-ramsize 256 --index-storage-setting "memopt"
# Create a bucket if it doesn't exist
cb_bucket_exists=$(curl -s -u admin:password http://couchbase:8091/pools/default/buckets | grep -c "ProcessingStatus")
if [ "$cb_bucket_exists" -eq 0 ]; then
echo "Creating bucket 'ProcessingStatus'..."
couchbase-cli bucket-create -c couchbase:8091 -u admin -p password \
--bucket=ProcessingStatus --bucket-type=couchbase --bucket-ramsize=100
fi
# Add a scope
echo "Adding scope 'data'..."
curl -s -u admin:password -X POST \
http://couchbase:8091/pools/default/buckets/ProcessingStatus/scopes \
-d name=data
# Add a collection under the scope
echo "Adding collection 'Reports' under scope 'data'..."
curl -s -u admin:password -X POST \
http://couchbase:8091/pools/default/buckets/ProcessingStatus/scopes/data/collections \
-d name=Reports
# Add a collection under the scope
echo "Adding collection 'Reports-DeadLetter' under scope 'data'..."
curl -s -u admin:password -X POST \
http://couchbase:8091/pools/default/buckets/ProcessingStatus/scopes/data/collections \
-d name=Reports-DeadLetter
# Done
echo "Couchbase Server initialized."
echo "Initialized" > /home/couchbase_initialized
echo "Couchbase setup completed."
else
echo "Couchbase Server already initialized."
fi