Add support of nginx webserver. Fix error in determin PHP version.
This commit is contained in:
parent
71959acebe
commit
f34ef5b05b
@ -275,53 +275,149 @@ if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
if [[ -z "$PHP_VERSION" ]] ; then
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
if $NGINX_IS_ENABLED ; then
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
fi
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
|
elif $APACHE2_IS_ENABLED ; then
|
||||||
|
|
||||||
|
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
||||||
|
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
||||||
|
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
PHP_VERSION="$(grep -o -E "php-?.{1}\..{1}-fpm" $VHOST_CONFIG_FILE | grep -o -E ".{1}\..{1}")"
|
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
||||||
|
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
||||||
|
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
||||||
|
fi
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
if [[ -z "$PHP_VERSION" ]] ; then
|
||||||
fatal "PHP Version must be givven if running PHP-FPM engine (parameter 'PHP_VERSION')"
|
|
||||||
|
warn "The PHP version was not specified and cannot be determined!"
|
||||||
|
|
||||||
|
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
echo ""
|
||||||
|
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
PHP_VERSION=
|
||||||
|
while [ "X$PHP_VERSION" = "X" ]
|
||||||
|
do
|
||||||
|
echononl " PHP main version: "
|
||||||
|
read PHP_VERSION
|
||||||
|
if [ "X$PHP_VERSION" = "X" ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
||||||
|
echo ""
|
||||||
|
PHP_VERSION=
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Determin user/group of the webserver
|
NGINX_IS_ENABLED=false
|
||||||
# -
|
APACHE2_IS_ENABLED=false
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
# Check if NGINX webserver is ctive
|
||||||
|
#
|
||||||
|
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
||||||
|
|
||||||
|
NGINX_IS_ENABLED=true
|
||||||
|
|
||||||
|
# - Determin user of the webserver
|
||||||
# -
|
# -
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
nginx_binary="$(which nginx)"
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
if [[ -z "$nginx_binary" ]] ; then
|
||||||
|
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
||||||
|
if [[ -z "$nginx_binary" ]] ; then
|
||||||
|
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
||||||
|
nginx_binary="/usr/local/nginx/bin/nginx"
|
||||||
|
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
||||||
|
nginx_binary="/usr/local/nginx/sbin/nginx"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -x "$nginx_binary" ]] ; then
|
||||||
|
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
||||||
|
fi
|
||||||
|
|
||||||
# - Is webserver running ?
|
# - Is webserver running ?
|
||||||
# -
|
# -
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
if [[ "X${PID}X" = "XX" ]] ;then
|
||||||
IS_HTTPD_RUNNING=false
|
IS_HTTPD_RUNNING=false
|
||||||
else
|
else
|
||||||
IS_HTTPD_RUNNING=true
|
IS_HTTPD_RUNNING=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
||||||
|
|
||||||
|
APACHE2_IS_ENABLED=true
|
||||||
|
|
||||||
|
# - Determin user of the webserver
|
||||||
|
# -
|
||||||
|
httpd_binary="`which httpd`"
|
||||||
|
if [ -z "$httpd_binary" ]; then
|
||||||
|
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
||||||
|
if [ -z "$httpd_binary" ]; then
|
||||||
|
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
||||||
|
httpd_binary="/usr/local/apache2/bin/httpd"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ -x "$httpd_binary" ];then
|
||||||
|
|
||||||
|
# - Determin websever user
|
||||||
|
# -
|
||||||
|
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
||||||
|
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
||||||
|
|
||||||
|
# - Is webserver running ?
|
||||||
|
# -
|
||||||
|
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
||||||
|
if [[ "X${PID}X" = "XX" ]] ;then
|
||||||
|
IS_HTTPD_RUNNING=false
|
||||||
|
else
|
||||||
|
IS_HTTPD_RUNNING=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/nno]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
if [[ -n "$_HTTP_USER" ]] ; then
|
||||||
@ -413,21 +509,97 @@ fi
|
|||||||
# -
|
# -
|
||||||
echo ""
|
echo ""
|
||||||
echononl " Stop Apache Webserver.."
|
echononl " Stop Apache Webserver.."
|
||||||
if $SYSTEMD_EXISTS ; then
|
if $APACHE2_IS_ENABLED ; then
|
||||||
systemctl stop apache2
|
if $IS_HTTPD_RUNNING ; then
|
||||||
if [[ $? -eq 0 ]]; then
|
if $SYSTEMD_EXISTS ; then
|
||||||
echo_ok
|
systemctl stop apache2
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
/etc/init.d/apache2 stop
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_skipped
|
||||||
fatal "$(cat $log_file)"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
/etc/init.d/apache2 stop
|
echo_skipped
|
||||||
if [[ $? -eq 0 ]]; then
|
fi
|
||||||
echo_ok
|
|
||||||
|
# - Stop Nginx Webservice
|
||||||
|
# -
|
||||||
|
echo ""
|
||||||
|
echononl " Stop Nginx Webserver.."
|
||||||
|
if $NGINX_IS_ENABLED ; then
|
||||||
|
if $IS_HTTPD_RUNNING ; then
|
||||||
|
if $SYSTEMD_EXISTS ; then
|
||||||
|
systemctl stop nginx
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
/etc/init.d/nginx stop
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_skipped
|
||||||
fatal "$(cat $log_file)"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -538,46 +710,101 @@ fi
|
|||||||
# -
|
# -
|
||||||
echo ""
|
echo ""
|
||||||
echononl " Start Apache Webserver.."
|
echononl " Start Apache Webserver.."
|
||||||
if $IS_HTTPD_RUNNING ; then
|
if $APACHE2_IS_ENABLED ; then
|
||||||
if $SYSTEMD_EXISTS ; then
|
if $IS_HTTPD_RUNNING ; then
|
||||||
systemctl start apache2 > $log_file 2>&1
|
if $SYSTEMD_EXISTS ; then
|
||||||
if [[ $? -eq 0 ]]; then
|
systemctl start apache2 > $log_file 2>&1
|
||||||
echo_ok
|
if [[ $? -eq 0 ]]; then
|
||||||
else
|
echo_ok
|
||||||
echo_failed
|
else
|
||||||
error "$(cat $log_file)"
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
echononl "continue anyway [yes/no]: "
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/no]: "
|
|
||||||
read OK
|
read OK
|
||||||
done
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
/etc/init.d/apache2 start > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
/etc/init.d/apache2 start > $log_file 2>&1
|
echo_skipped
|
||||||
if [[ $? -eq 0 ]]; then
|
warn "The webserver was not running, so it will be keept down!"
|
||||||
echo_ok
|
fi
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_skipped
|
||||||
error "$(cat $log_file)"
|
fi
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
# - Start NGINX Webservise
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
# -
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
echo ""
|
||||||
echononl "Wrong entry! - repeat [yes/no]: "
|
echononl " Start Nginx Webserver.."
|
||||||
read OK
|
if $NGINX_IS_ENABLED ; then
|
||||||
done
|
if $IS_HTTPD_RUNNING ; then
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
if $SYSTEMD_EXISTS ; then
|
||||||
fi
|
systemctl start nginx > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
/etc/init.d/nginx start > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "$(cat $log_file)"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/no]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
warn "The NGINX is not configured as active - so nothing to do."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
warn "The webserver was not running, so it will be keept down!"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_redis_cli_bin="$(which redis-cli)"
|
_redis_cli_bin="$(which redis-cli)"
|
||||||
|
Loading…
Reference in New Issue
Block a user