Merge pull request #2906 from manuel-colmenero/master

fix: Check the location of nginx in a central way
This commit is contained in:
Jose Diaz-Gonzalez
2017-09-19 13:53:21 -04:00
committed by GitHub

View File

@@ -6,14 +6,36 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
get_nginx_location() {
declare desc="check that nginx is at the expected location and return it"
local NGINX_LOCATION
NGINX_LOCATION=$(which nginx 2>/dev/null)
if [[ -z "$NGINX_LOCATION" ]]; then
NGINX_LOCATION="/usr/sbin/nginx"
fi
if [[ ! -x "$NGINX_LOCATION" ]]; then
dokku_log_fail "Could not find nginx binary in \$PATH or at '${NGINX_LOCATION}'."
fi
echo "$NGINX_LOCATION"
}
validate_nginx() {
declare desc="validate entire nginx config"
local NGINX_LOCATION
NGINX_LOCATION=$(get_nginx_location)
if [[ -z "$NGINX_LOCATION" ]]; then
exit 1;
fi
set +e
sudo /usr/sbin/nginx -t > /dev/null 2>&1
sudo "$NGINX_LOCATION" -t > /dev/null 2>&1
local exit_code=$?
set -e
if [[ "$exit_code" -ne "0" ]]; then
sudo /usr/sbin/nginx -t
sudo "$NGINX_LOCATION" -t
shopt -s nullglob
local conf_file
for conf_file in $DOKKU_ROOT/*/nginx.conf; do
@@ -152,11 +174,6 @@ is_spdy_enabled() {
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
local HAS_SUPPORT=true
if ! which nginx > /dev/null 2>&1; then
echo $HAS_SUPPORT
return
fi
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
@@ -179,11 +196,6 @@ is_http2_enabled() {
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
local HAS_SUPPORT=false
if ! which nginx > /dev/null 2>&1; then
echo $HAS_SUPPORT
return
fi
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
@@ -281,9 +293,14 @@ nginx_build_config() {
done
fi
local NGINX_VERSION="$(nginx -v 2>&1 | cut -d'/' -f 2)"
local SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
local HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED
NGINX_LOCATION=$(get_nginx_location)
if [[ -z "$NGINX_LOCATION" ]]; then
exit 1;
fi
NGINX_VERSION="$("$NGINX_LOCATION" -v 2>&1 | cut -d'/' -f 2)"
SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
eval "$(config_export app "$APP")"
local SIGIL_PARAMS=(-f $NGINX_TEMPLATE APP="$APP" DOKKU_ROOT="$DOKKU_ROOT"