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

  1. #!/bin/bash
  2. . lib/common
  3. set -e
  4. DBNAME=$(relation-get dbname) || {
  5. DBNAME="${BASE_SERVICE_NAME//\./_}"
  6. relation-set dbname "$DBNAME"
  7. }
  8. cmd="rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: '$TARGET_SERVICE_NAME:27017' } ]})"
  9. debug "${WHITE}running:$NORMAL $cmd"
  10. out=$(ddb < <(echo "use $DBNAME";
  11. echo "$cmd"))
  12. if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]]; then
  13. exit 0
  14. fi
  15. if [[ "$out" == *"\"ok\" : 1"* ]]; then
  16. exit 0
  17. fi
  18. err Replicate Set initialisation failed
  19. echo "$out" >&2