Merge pull request #7582 from dokku/6967-global-vhost-disable

Add ability to disable vhosts for all apps
This commit is contained in:
Jose Diaz-Gonzalez
2025-03-10 12:46:58 -05:00
committed by GitHub
6 changed files with 79 additions and 14 deletions

View File

@@ -4,6 +4,57 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
fn-domains-clear() {
declare desc="clear all domains for one or more apps"
declare APP="$1"
if [[ "$APP" == "--all" ]]; then
for APP in $(dokku_apps); do
fn-domains-clear-app "$APP"
done
else
fn-domains-clear-app "$APP"
fi
}
fn-domains-clear-app() {
declare desc="clear all domains for an app"
declare APP="$1"
local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
rm -f "$APP_VHOST_PATH"
domains_setup "$APP"
plugn trigger post-domains-update "$APP" "clear"
dokku_log_info1 "Cleared domains in $APP"
}
fn-domains-disable() {
declare desc="disable domains/VHOST support"
declare APP="$1"
if [[ "$APP" == "--all" ]]; then
for APP in $(dokku_apps); do
domains_disable "$APP"
done
else
domains_disable "$APP"
fi
}
fn-domains-enable() {
declare desc="enable domains/VHOST support"
declare APP="$1"
if [[ "$APP" == "--all" ]]; then
for APP in $(dokku_apps); do
domains_enable "$APP"
done
else
domains_enable "$APP"
fi
}
disable_app_vhost() {
declare desc="disable vhost support for given application"
declare APP=$1 RESTART_APP="$2"
@@ -17,6 +68,9 @@ disable_app_vhost() {
[[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP
DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS $APP NO_VHOST=1
if [[ "$RESTART_APP" == "--no-restart" ]]; then
plugn trigger post-domains-update "$APP" "disable"
fi
}
domains_setup() {
@@ -110,7 +164,7 @@ domains_disable() {
touch "$APP_VHOST_PATH"
if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then
disable_app_vhost "$APP"
disable_app_vhost "$APP" --no-restart
else
dokku_log_info1 "Domains (VHOST) support is already disabled for app ($APP)"
fi
@@ -196,6 +250,9 @@ enable_app_vhost() {
plugn trigger pre-enable-vhost "$APP"
[[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP
DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS "$APP" NO_VHOST=0
if [[ "$RESTART_APP" == "--no-restart" ]]; then
plugn trigger post-domains-update "$APP" "enable"
fi
}
get_app_domains() {

View File

@@ -10,13 +10,8 @@ cmd-domains-clear() {
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
verify_app_name "$APP"
local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
rm -f "$APP_VHOST_PATH"
domains_setup "$APP"
plugn trigger post-domains-update "$APP" "clear"
dokku_log_info1 "Cleared domains in $APP"
[[ "$APP" == "--all" ]] || verify_app_name "$APP"
fn-domains-clear "$APP"
}
cmd-domains-clear "$@"

View File

@@ -10,8 +10,8 @@ cmd-domains-disable() {
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
verify_app_name "$APP"
domains_disable "$APP"
[[ "$APP" == "--all" ]] && verify_app_name "$APP"
fn-domains-disable "$APP"
}
cmd-domains-disable "$@"

View File

@@ -10,8 +10,8 @@ cmd-domains-enable() {
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
verify_app_name "$APP"
domains_enable "$APP"
[[ "$APP" == "--all" ]] && verify_app_name "$APP"
fn-domains-enable "$APP"
}
cmd-domains-enable "$@"