fork 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.

72 lines
2.0 KiB

  1. # -*- mode: shell-script -*-
  2. CYCLOS_CONFIG="/usr/local/cyclos/WEB-INF/classes/cyclos.properties"
  3. HOST_CYCLOS_CONFIG="$SERVICE_CONFIGSTORE$CYCLOS_CONFIG"
  4. cyclos:build() {
  5. docker pull "$DOCKER_BASE_IMAGE" || return 1
  6. mkdir -p "$(dirname "$HOST_CYCLOS_CONFIG")"
  7. container_id=$(docker run -d --entrypoint true "$DOCKER_BASE_IMAGE") || return 1
  8. mkdir -p "$(dirname "$HOST_CYCLOS_CODE")" &&
  9. docker cp "$container_id":"$CYCLOS_CONFIG" "$HOST_CYCLOS_CONFIG" &&
  10. docker rm "$container_id"
  11. }
  12. named-relation-get-target-service() {
  13. local relation="$1" ts
  14. if ! read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "$relation"); then
  15. err "Couldn't find relation ${DARKCYAN}$relation${NORMAL}."
  16. return 1
  17. fi
  18. e "$ts"
  19. }
  20. ## XXXvlab: Consider for inclusion in compose-core
  21. relation-get-config() {
  22. local relation="$1" ts relation_dir
  23. ts=$(named-relation-get-target-service "$relation") || return 1
  24. relation_dir=$(get_relation_data_dir "$SERVICE_NAME" "$ts" "$relation") || return 1
  25. cat "${relation_dir}/data"
  26. }
  27. named-relation-get() {
  28. local relation="$1" key="$2" config
  29. config=$(relation-get-config "$relation") || return 1
  30. e "$config" | shyaml get-value "$key" || {
  31. err "Couldn't get ${WHITE}$key${NORMAL} value" \
  32. "in ${DARKCYAN}$relation${NORMAL} relation's data."
  33. exit 1
  34. }
  35. }
  36. sql() {
  37. (
  38. DBNAME="$(named-relation-get "postgres-database" dbname)" || exit 1
  39. ts=$(named-relation-get-target-service "postgres-database") || exit 1
  40. export SERVICE_NAME="$ts"
  41. export SERVICE_DATASTORE="$DATASTORE/$SERVICE_NAME"
  42. DOCKER_BASE_IMAGE=$(service_base_docker_image "$SERVICE_NAME")
  43. export DOCKER_BASE_IMAGE
  44. target_charm=$(get_service_charm "$ts") || exit 1
  45. target_charm_path=$(charm.get_dir "$target_charm") || exit 1
  46. set +e
  47. . "$target_charm_path/lib/common"
  48. set -e
  49. ensure_db_docker_running
  50. ddb "$DBNAME"
  51. )
  52. }