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.

59 lines
1.7 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. if [ -z "$RELATION_DATA_FILE" ]; then
  10. err "$FUNCNAME: relation does not seems to be correctly setup."
  11. exit 1
  12. fi
  13. if ! [ -r "$RELATION_DATA_FILE" ]; then
  14. err "$FUNCNAME: can't read relation's data." >&2
  15. exit 1
  16. fi
  17. if [ "$(cat "$RELATION_DATA_FILE" | shyaml get-type)" == "str" ]; then
  18. ## Cached version already there
  19. ## Note that we rely on the fact that when the relations
  20. ## options are changed in the `compose.yml` file, the relation
  21. ## data file is recreated from the values of the
  22. ## `compose.yml`.
  23. info "Previous relation data is still valid."
  24. exit 0
  25. fi
  26. . lib/common
  27. schedule=$(relation-get schedule) || true
  28. lock_opts=(-D -p 10)
  29. command=(
  30. docker run --rm \
  31. --network ${PROJECT_NAME}_default \
  32. -v "$LOCAL_DB_PASSFILE":/root/.my.cnf \
  33. -v "$HOST_CHARM_STORE/${CHARM_REL_PATH#${CHARM_STORE}/}/resources/bin/mysql-backup:/usr/sbin/mysql-backup" \
  34. -v "$SERVICE_DATASTORE/var/backups/mysql:/var/backups/mysql" \
  35. --entrypoint mysql-backup \
  36. "$DOCKER_BASE_IMAGE" --host "${SERVICE_NAME}"
  37. )
  38. quoted_command=()
  39. for arg in "${command[@]}"; do
  40. quoted_command+=("$(printf "%q" "$arg")")
  41. done
  42. printf "(%s) {%s} %s\n" \
  43. "$schedule" \
  44. "${lock_opts[*]}" \
  45. "${quoted_command[*]}" > "$RELATION_DATA_FILE"