forked from 0k/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.
86 lines
2.5 KiB
86 lines
2.5 KiB
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
service:relations() {
|
|
local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$2" \
|
|
rn ts rc td
|
|
if [ -e "$cache_file" ]; then
|
|
#debug "$FUNCNAME: SESSION cache hit $1"
|
|
cat "$cache_file"
|
|
return 0
|
|
fi
|
|
|
|
while read-0-err E rn ts rc td; do
|
|
[ "$relation" == "$rn" ] && {
|
|
printf "%s\0" "$ts" "$rc" "$td"
|
|
}
|
|
done < <(p-err get_service_relations "$service") > "$cache_file"
|
|
if [ "$E" != 0 ]; then
|
|
rm -f "$cache_file" ## no cache
|
|
return 1
|
|
fi
|
|
cat "$cache_file"
|
|
}
|
|
export -f service:relations
|
|
|
|
|
|
|
|
export TRAVERSE_SEPARATOR=:
|
|
## Traverse on all service satisfying relation
|
|
service:traverse:all() {
|
|
local service_path="$1"
|
|
local service relation path relation
|
|
service=${service_path%%$TRAVERSE_SEPARATOR*}
|
|
path=${service_path#*$TRAVERSE_SEPARATOR}
|
|
if [[ "$path" == *$TRAVERSE_SEPARATOR* ]]; then
|
|
relation=${path%%$TRAVERSE_SEPARATOR*}
|
|
path=${path#*$TRAVERSE_SEPARATOR}
|
|
else
|
|
relation=$path
|
|
path=
|
|
fi
|
|
while read-0-err E ts _ _; do
|
|
if [ -n "$path" ]; then
|
|
service:traverse "$ts$TRAVERSE_SEPARATOR$path"
|
|
else
|
|
printf "%s\n" "$ts"
|
|
fi
|
|
done < <(p-err service:relations "${service}" "${relation}")
|
|
if [ "$E" != 0 ]; then
|
|
err "Couldn't find service for ${DARKYELLOW}$service${NORMAL}--${DARKCYAN}$relation${NORMAL}--> ?"
|
|
return 1
|
|
fi
|
|
}
|
|
export -f service:traverse:all
|
|
|
|
|
|
##
|
|
## Finish live connection for relation nextcloud_app
|
|
##
|
|
|
|
nextcloud_services=($(service:traverse:all "$MASTER_BASE_SERVICE_NAME":nextcloud-app)) || return 1
|
|
|
|
if [ ${#nextcloud_services[@]} != 0 ]; then
|
|
if ! collabora_url=$(relation:get "$MASTER_BASE_SERVICE_NAME":web-proxy url) || [ -z "$collabora_url" ]; then
|
|
collabora_url="http://$BASE_SERVICE_NAME:9980"
|
|
fi
|
|
if ! get_healthy_container_ip_for_service "$SERVICE_NAME" 9980; then
|
|
exit 17
|
|
fi
|
|
|
|
info "collabora_domain: '$collabora_url'"
|
|
|
|
for nextcloud_service in "${nextcloud_services[@]}"; do
|
|
|
|
## Activate-config will make nextcloud try to connect to collabora.
|
|
## This is why we must run this in post_deploy
|
|
|
|
compose --no-relations --no-init \
|
|
occ "$nextcloud_service" \
|
|
app:install richdocuments \; \
|
|
config:app:set --value="${collabora_url}" richdocuments wopi_url \; \
|
|
richdocuments:activate-config || return 1
|
|
|
|
done
|
|
fi
|