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.

64 lines
1.8 KiB

  1. #!/bin/bash
  2. ## When writing relation script, remember:
  3. ## - they should be idempotents
  4. ## - they can be launched while the dockers is already up
  5. ## - they are launched from the host
  6. ## - the target of the link is launched first, and get a chance to ``relation-set``
  7. ## - both side of the scripts get to use ``relation-get``.
  8. ## - use actions of other side for other side's business logic
  9. . lib/common
  10. if [ -z "$RELATION_DATA_FILE" ]; then
  11. err "$FUNCNAME: relation does not seems to be correctly setup."
  12. exit 1
  13. fi
  14. if ! [ -r "$RELATION_DATA_FILE" ]; then
  15. err "$FUNCNAME: can't read relation's data." >&2
  16. exit 1
  17. fi
  18. if [ "$(cat "$RELATION_DATA_FILE" | shyaml get-type)" == "str" ]; then
  19. ## Cached version already there
  20. ## Note that we rely on the fact that when the relations
  21. ## options are changed in the `compose.yml` file, the relation
  22. ## data file is recreated from the values of the
  23. ## `compose.yml`.
  24. info "Previous relation data is still valid."
  25. exit 0
  26. fi
  27. schedule=$(relation-get schedule) || true
  28. exclude_dbs=$(relation-get exclude-dbs 2>/dev/null) || true
  29. exclude_dbs=$(echo "$exclude_dbs" | shyaml get-values 2>/dev/null |
  30. nspc) || true
  31. lock_opts=(-D -p 10)
  32. command=(
  33. docker run --rm
  34. -u 0
  35. -e MONGO_HOST=${SERVICE_NAME}
  36. -e exclude_dbs="$exclude_dbs"
  37. --network ${PROJECT_NAME}_default
  38. -v "$HOST_CHARM_STORE/${CHARM_REL_PATH#${CHARM_STORE}/}/resources/bin/mongo-backup:/usr/sbin/mongo-backup"
  39. -v "$SERVICE_DATASTORE/var/backups/mongo:/var/backups/mongo"
  40. --entrypoint mongo-backup
  41. "$DOCKER_BASE_IMAGE"
  42. )
  43. quoted_command=()
  44. for arg in "${command[@]}"; do
  45. quoted_command+=("$(printf "%q" "$arg")")
  46. done
  47. printf "(%s) {%s} %s\n" \
  48. "$schedule" \
  49. "${lock_opts[*]}" \
  50. "${quoted_command[*]}" > "$RELATION_DATA_FILE"