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.

89 lines
2.2 KiB

  1. #!/bin/bash
  2. ## Load action gets a first argument a DIRECTORY holding the necessary files.
  3. ##
  4. ##
  5. if [ -z "$SERVICE_DATASTORE" ]; then
  6. echo "This script is meant to be run through 'compose' to work properly." >&2
  7. exit 1
  8. fi
  9. usage="$exname [-h|--help] DBNAME [MODULE ...]"
  10. dbname=
  11. modules=()
  12. while [ "$1" ]; do
  13. case "$1" in
  14. "--help"|"-h")
  15. print_usage
  16. exit 0
  17. ;;
  18. *)
  19. [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; }
  20. modules+=("$1")
  21. ;;
  22. esac
  23. shift
  24. done
  25. [ "${modules[*]}" ] || modules=("all")
  26. modules="$(echo "${modules[@]}" | tr " " ",")"
  27. ## This can work only if ~/.my.cnf is correctly created by init.
  28. if [ -z "$dbname" ]; then
  29. ##
  30. ## Fetch default dbname in relation to postgres-database
  31. ##
  32. ## XXXvlab: can't get real config here
  33. if ! read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "postgres-database"); then
  34. err "Couldn't find relation ${DARKCYAN}postgres-database${NORMAL}."
  35. exit 1
  36. fi
  37. relation_file=$(get_relation_data_dir "$SERVICE_NAME" "$ts" "postgres-database") || {
  38. err "Failed to find relation file"
  39. exit 1
  40. }
  41. postgres_config=$(cat "$relation_file"/data) || exit 2
  42. dbname="$(e "$postgres_config" | shyaml get-value dbname)" || {
  43. err "Couldn't retrieve information of ${DARKCYAN}postgres-database${NORMAL}'s relation."
  44. exit 1
  45. }
  46. fi
  47. running_containers=($(get_running_containers_for_service "$SERVICE_NAME")) || {
  48. err "Failed to get running containers for service $DARKYELLOW$SERVICE_NAME$NORMAL."
  49. exit 1
  50. }
  51. stopped_containers=()
  52. for container in "${running_containers[@]}"; do
  53. ## stop container
  54. docker stop "$container" || {
  55. err "Failed to stop container $container."
  56. exit 1
  57. }
  58. stopped_containers+=("$container")
  59. done
  60. restart_stopped_container() {
  61. for container in "${stopped_containers[@]}"; do
  62. docker start "$container" || {
  63. err "Failed to start container $container."
  64. exit 1
  65. }
  66. done
  67. }
  68. trap restart_stopped_container EXIT
  69. set -e
  70. launch_docker_compose run "$SERVICE_NAME" --update="$modules" -d "$dbname" --stop-after-init
  71. info "Updated '$modules' module(s) into database '$dbname'."