fix: Check the location of nginx in a central way
- Now there's only a "single source of truth" for the location of the nginx binary. - It is checked if it's there before it's needed.
This commit is contained in:
1 parent
3a81c8f279
commit
3d785360e1
1 file changed
+22
-13
@@ -6,14 +6,29 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
|||||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/ps/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="/usr/sbin/nginx"
|
||||||
|
if ! [ -x "$NGINX_LOCATION" ]; then
|
||||||
|
dokku_log_fail "Could not find nginx binary at ${NGINX_LOCATION}."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
echo "$NGINX_LOCATION"
|
||||||
|
}
|
||||||
|
|
||||||
validate_nginx() {
|
validate_nginx() {
|
||||||
declare desc="validate entire nginx config"
|
declare desc="validate entire nginx config"
|
||||||
|
local NGINX_LOCATION=$(get_nginx_location)
|
||||||
|
if [ -z "$NGINX_LOCATION" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
sudo /usr/sbin/nginx -t > /dev/null 2>&1
|
sudo "$NGINX_LOCATION" -t > /dev/null 2>&1
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
set -e
|
set -e
|
||||||
if [[ "$exit_code" -ne "0" ]]; then
|
if [[ "$exit_code" -ne "0" ]]; then
|
||||||
sudo /usr/sbin/nginx -t
|
sudo "$NGINX_LOCATION" -t
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
local conf_file
|
local conf_file
|
||||||
for conf_file in $DOKKU_ROOT/*/nginx.conf; do
|
for conf_file in $DOKKU_ROOT/*/nginx.conf; do
|
||||||
@@ -152,11 +167,6 @@ is_spdy_enabled() {
|
|||||||
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
||||||
local HAS_SUPPORT=true
|
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]}')
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
||||||
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
||||||
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
||||||
@@ -179,11 +189,6 @@ is_http2_enabled() {
|
|||||||
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
local MAJOR_VERSION MINOR_VERSION PATCH_VERSION
|
||||||
local HAS_SUPPORT=false
|
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]}')
|
MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}')
|
||||||
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}')
|
||||||
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}')
|
||||||
@@ -281,7 +286,11 @@ nginx_build_config() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NGINX_VERSION="$(nginx -v 2>&1 | cut -d'/' -f 2)"
|
local NGINX_LOCATION=$(get_nginx_location)
|
||||||
|
if [ -z "$NGINX_LOCATION" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
local NGINX_VERSION="$("$NGINX_LOCATION" -v 2>&1 | cut -d'/' -f 2)"
|
||||||
local SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
|
local SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
|
||||||
local HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
|
local HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user