2017-02-20 22:35:52 -07:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
2017-02-20 22:35:52 -07:00
|
|
|
|
2018-12-30 08:33:53 -05:00
|
|
|
nginx_vhosts_validate_single_func() {
|
|
|
|
|
declare APP="$1" FLAG="$2"
|
|
|
|
|
local NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$NGINX_CONF" ]]; then
|
|
|
|
|
dokku_log_warn_quiet "No nginx config found for ${APP}"
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if nginx_vhosts_is_valid_nginx_config_func "$APP"; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
dokku_log_warn "Failed to validate nginx config for ${APP}. Contents below..."
|
|
|
|
|
cat "$NGINX_CONF"
|
|
|
|
|
|
|
|
|
|
if [[ "$FLAG" == "--clean" ]]; then
|
|
|
|
|
nginx_vhosts_conf_clean_func "$APP"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nginx_vhosts_is_valid_nginx_config_func() {
|
|
|
|
|
declare desc="checks if an app has a valid nginx config"
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
local VALIDATE_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/validate.conf.sigil"
|
|
|
|
|
local TMP_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
|
2019-02-02 13:49:24 -05:00
|
|
|
trap 'rm -rf "$TMP_OUTPUT" >/dev/null' RETURN INT TERM EXIT
|
2018-12-30 08:33:53 -05:00
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
sigil -f "$VALIDATE_TEMPLATE" NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf" | cat -s >"$TMP_OUTPUT"
|
|
|
|
|
sudo "$NGINX_LOCATION" -t -c "$TMP_OUTPUT" 2>/dev/null
|
2018-12-30 08:33:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nginx_vhosts_conf_clean_func() {
|
|
|
|
|
declare APP="$1"
|
|
|
|
|
local NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
dokku_log_warn "Removing invalid nginx file"
|
|
|
|
|
rm -f "$NGINX_CONF"
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 22:35:52 -07:00
|
|
|
nginx_vhosts_help_content_func() {
|
2019-01-07 01:04:17 -05:00
|
|
|
declare desc="return nginx plugin help content"
|
|
|
|
|
cat <<help_content
|
2017-02-20 22:35:52 -07:00
|
|
|
nginx:build-config <app>, (Re)builds nginx config for given app
|
|
|
|
|
nginx:access-logs <app> [-t], Show the nginx access logs for an application (-t follows)
|
|
|
|
|
nginx:error-logs <app> [-t], Show the nginx error logs for an application (-t follows)
|
2018-12-30 08:33:53 -05:00
|
|
|
nginx:validate [<app>] [--clean], Validates and optionally cleans up invalid nginx configurations
|
2017-02-20 22:35:52 -07:00
|
|
|
help_content
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nginx_vhosts_help_cmd() {
|
2019-01-07 01:04:17 -05:00
|
|
|
if [[ $1 == "nginx:help" ]]; then
|
2017-02-20 22:35:52 -07:00
|
|
|
echo -e 'Usage: dokku nginx[:COMMAND]'
|
|
|
|
|
echo ''
|
|
|
|
|
echo 'Interact with Dokku'"'"'s Nginx proxy.'
|
|
|
|
|
echo ''
|
|
|
|
|
echo 'Additional commands:'
|
|
|
|
|
nginx_vhosts_help_content_func | sort | column -c2 -t -s,
|
|
|
|
|
elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then
|
|
|
|
|
nginx_vhosts_help_content_func
|
|
|
|
|
else
|
2019-01-07 01:04:17 -05:00
|
|
|
cat <<help_desc
|
2017-02-20 22:35:52 -07:00
|
|
|
nginx, Interact with Dokku's Nginx proxy
|
|
|
|
|
help_desc
|
|
|
|
|
fi
|
|
|
|
|
}
|
2018-07-26 09:53:56 -04:00
|
|
|
|
|
|
|
|
nginx_clear_config() {
|
|
|
|
|
declare desc="Remove the nginx conf file"
|
2019-01-07 01:04:17 -05:00
|
|
|
declare APP="$1"
|
2018-07-26 09:53:56 -04:00
|
|
|
rm -f "$DOKKU_ROOT/$APP/nginx.conf"
|
|
|
|
|
}
|