From 38990109f5fd8c11106419a8a1ee5878df58536a Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 18 Feb 2019 08:34:46 +0100 Subject: [PATCH] new: dev: [apache] support when called out from a relation. This is to support ``ssh-tunnel`` that will be called from ``init``. --- apache/lib/common | 16 +++++++++++----- apache/test/vhost_cert_provider | 1 + apache/test/vhost_files | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apache/lib/common b/apache/lib/common index 850f1cb1..b9ebdc49 100644 --- a/apache/lib/common +++ b/apache/lib/common @@ -56,7 +56,9 @@ apache_vhost_create() { protocols=$(__vhost_cfg_normalize_protocol "$cfg") || return 1 fi - domain=$(get_domain "$cfg") && relation-set domain "$domain" + domain=$(get_domain "$cfg") && { + [ "$RELATION_DATA_FILE" ] && relation-set domain "$domain" + } if is_protocol_enabled https "$protocols"; then if [ -z "$domain" ]; then @@ -80,7 +82,8 @@ apache_vhost_create() { RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,QSA] " - relation-set apache-custom-rules "$redirect_rule + [ "$RELATION_DATA_FILE" ] && \ + relation-set apache-custom-rules "$redirect_rule $(if [ "$custom_rules" ]; then echo "- |"$'\n'"$(echo "$custom_rules" | prefix " ")" fi)" @@ -89,14 +92,17 @@ $(if [ "$custom_rules" ]; then echo "- |"$'\n'"$(echo "$custom_rules" | prefix " ")" fi)")") fi - relation-set protocol https + [ "$RELATION_DATA_FILE" ] && \ + relation-set protocol https else ## Both services are available and different, don't do anything then ? - #relation-set protocol https + #[ "$RELATION_DATA_FILE" ] && \ + # relation-set protocol https : fi else - relation-set protocol http + [ "$RELATION_DATA_FILE" ] && \ + relation-set protocol http fi vhost_statement=$(apache_vhost_statement "$type" "$protocols" "$cfg" "$domain") || { err "Failed to get vhost statement for type $type on ${protocols:1:-1}" diff --git a/apache/test/vhost_cert_provider b/apache/test/vhost_cert_provider index b7f83954..69a7af07 100644 --- a/apache/test/vhost_cert_provider +++ b/apache/test/vhost_cert_provider @@ -24,6 +24,7 @@ relation-get() { } export -f relation-get +export RELATION_DATA_FILE=x relation-set() { local key="$1" value="$2" echo "relation-set $key:" >&2 diff --git a/apache/test/vhost_files b/apache/test/vhost_files index a0309868..ff43e2a2 100644 --- a/apache/test/vhost_files +++ b/apache/test/vhost_files @@ -22,6 +22,7 @@ relation-get() { } export -f relation-get +export RELATION_DATA_FILE=x relation-set() { local key="$1" value="$2" echo "relation-set $key:" >&2