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

#!/bin/bash
## Load action gets a first argument a DIRECTORY holding the necessary files.
##
##
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
usage="$exname [-h|--help] DBNAME [MODULE ...]"
dbname=
modules=()
while [ "$1" ]; do
case "$1" in
"--help"|"-h")
print_usage
exit 0
;;
*)
[ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; }
modules+=("$1")
;;
esac
shift
done
[ "${modules[*]}" ] || modules=("all")
modules="$(echo "${modules[@]}" | tr " " ",")"
## This can work only if ~/.my.cnf is correctly created by init.
if [ -z "$dbname" ]; then
##
## Fetch default dbname in relation to postgres-database
##
## XXXvlab: can't get real config here
if ! read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "postgres-database"); then
err "Couldn't find relation ${DARKCYAN}postgres-database${NORMAL}."
exit 1
fi
relation_file=$(get_relation_data_dir "$SERVICE_NAME" "$ts" "postgres-database") || {
err "Failed to find relation file"
exit 1
}
postgres_config=$(cat "$relation_file"/data) || exit 2
dbname="$(e "$postgres_config" | shyaml get-value dbname)" || {
err "Couldn't retrieve information of ${DARKCYAN}postgres-database${NORMAL}'s relation."
exit 1
}
fi
running_containers=($(get_running_containers_for_service "$SERVICE_NAME")) || {
err "Failed to get running containers for service $DARKYELLOW$SERVICE_NAME$NORMAL."
exit 1
}
stopped_containers=()
for container in "${running_containers[@]}"; do
## stop container
docker stop "$container" || {
err "Failed to stop container $container."
exit 1
}
stopped_containers+=("$container")
done
restart_stopped_container() {
for container in "${stopped_containers[@]}"; do
docker start "$container" || {
err "Failed to start container $container."
exit 1
}
done
}
trap restart_stopped_container EXIT
set -e
launch_docker_compose run "$SERVICE_NAME" --update="$modules" -d "$dbname" --stop-after-init
info "Updated '$modules' module(s) into database '$dbname'."