forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
538 B
29 lines
538 B
#!/bin/bash
|
|
|
|
. lib/common
|
|
|
|
set -e
|
|
|
|
DBNAME=$(relation-get dbname) || {
|
|
DBNAME="${BASE_SERVICE_NAME//\./_}"
|
|
relation-set dbname "$DBNAME"
|
|
}
|
|
|
|
|
|
cmd="rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: '$TARGET_SERVICE_NAME:27017' } ]})"
|
|
debug "${WHITE}running:$NORMAL $cmd"
|
|
|
|
out=$(ddb < <(echo "use $DBNAME";
|
|
echo "$cmd"))
|
|
|
|
if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [[ "$out" == *"\"ok\" : 1"* ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
err Replicate Set initialisation failed
|
|
echo "$out" >&2
|
|
|