From d221337bbde48e0724001c4d33ab72981f45d1f6 Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Wed, 1 May 2024 19:37:06 +0300 Subject: [PATCH] Added fixes for hestiacp for rpm installer --- bin/v-check-service-config | 51 +++++++++++++++++++++++++++++++++ bin/v-delete-web-domain-backend | 2 +- bin/v-restart-ftp | 8 ++++-- bin/v-restart-proxy | 25 ++++++++++++---- bin/v-restart-web | 29 +++++++++++++++++-- func/domain.sh | 4 +++ 6 files changed, 108 insertions(+), 11 deletions(-) create mode 100755 bin/v-check-service-config diff --git a/bin/v-check-service-config b/bin/v-check-service-config new file mode 100755 index 0000000..5a0e25b --- /dev/null +++ b/bin/v-check-service-config @@ -0,0 +1,51 @@ +#!/bin/bash +# info: check service config +# options: [SERVICE NAME] +# +# example: v-restart-web +# +# This function return status of service check config. + +#----------------------------------------------------------# +# Variables & Functions # +#----------------------------------------------------------# + +# Includes +# shellcheck source=/etc/hestiacp/hestia.conf +source /etc/hestiacp/hestia.conf +# shellcheck source=/usr/local/hestia/func/main.sh +source $HESTIA/func/main.sh +# load config file +source_conf "$HESTIA/conf/hestia.conf" + +date=$(date +"%Y-%m-%d %H:%M:%S") +DEBUG_LOG_FILE="/var/log/hestia/debug.log" + +[[ -f /etc/redhat-release ]] || exit 0 + +[[ -n "$1" ]] || exit 1 + +[[ -n "$2" ]] || DEBUG_LOG_FILE="$2" + +SERVICE_NAME="$1" + +case "$SERVICE_NAME" in +nginx ) + /usr/sbin/nginx -t >> "$DEBUG_LOG_FILE" 2>&1 + V_RESULT=$? + exit $V_RESULT +;; +httpd ) + /usr/sbin/httpd -t >> "$DEBUG_LOG_FILE" 2>&1 + V_RESULT=$? + exit $V_RESULT +;; +* ) + exit 0 +;; +esac + +# Something like error, we shouldn't be here +exit 1 + + diff --git a/bin/v-delete-web-domain-backend b/bin/v-delete-web-domain-backend index 464b55d..51bf51f 100755 --- a/bin/v-delete-web-domain-backend +++ b/bin/v-delete-web-domain-backend @@ -53,7 +53,7 @@ BACKEND="$template" # Defining pool directory if [ -f "/etc/redhat-release" ]; then - pool=$(find -L /etc/opt/remi/php80/ -name "$domain.conf" -exec dirname {} \;) + pool=$(find -L /etc/opt/remi/ -name "$domain.conf" -exec dirname {} \;) else pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;) fi diff --git a/bin/v-restart-ftp b/bin/v-restart-ftp index df026a3..57c5931 100755 --- a/bin/v-restart-ftp +++ b/bin/v-restart-ftp @@ -23,8 +23,12 @@ send_email_report() { email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $FTP_SYSTEM restart failed" - service "$FTP_SYSTEM" configtest >> $tmpfile 2>&1 - service "$FTP_SYSTEM" restart >> $tmpfile 2>&1 + if [ -f /etc/redhat-release ]; then + systemctl restart "$FTP_SYSTEM" >> $tmpfile 2>&1 + else + service "$FTP_SYSTEM" configtest >> $tmpfile 2>&1 + service "$FTP_SYSTEM" restart >> $tmpfile 2>&1 + fi cat $tmpfile | $SENDMAIL -s "$subj" $email rm -f $tmpfile } diff --git a/bin/v-restart-proxy b/bin/v-restart-proxy index 9ea8fec..0e61f00 100755 --- a/bin/v-restart-proxy +++ b/bin/v-restart-proxy @@ -70,13 +70,20 @@ if [ -f "$HESTIA/web/inc/nginx_proxy" ]; then if [ "$1" = 'background' ]; then # Restart system sleep 15 - # Preform a check if Nginx is valid as reload doesn't throw an error / exit if [ "$DEBUG_MODE" = "true" ]; then echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1 - service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$PROXY_SYSTEM" /var/log/hestia/debug.log + else + service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + fi else - service $PROXY_SYSTEM configtest > /dev/null 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$PROXY_SYSTEM" /dev/null + else + service $PROXY_SYSTEM configtest > /dev/null 2>&1 + fi fi if [ $? -ne 0 ]; then send_email_report @@ -100,9 +107,17 @@ else # Preform a check if Nginx is valid as reload doesn't throw an error / exit if [ "$DEBUG_MODE" = "true" ]; then echo "[ $date | $PROXY_SYSTEM ]" >> /var/log/hestia/debug.log 2>&1 - service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$PROXY_SYSTEM" /var/log/hestia/debug.log + else + service $PROXY_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + fi else - service $PROXY_SYSTEM configtest > /dev/null 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$PROXY_SYSTEM" /dev/null + else + service $PROXY_SYSTEM configtest > /dev/null 2>&1 + fi fi if [ $? -ne 0 ]; then send_email_report diff --git a/bin/v-restart-web b/bin/v-restart-web index 2ddd88f..332bb21 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -28,7 +28,11 @@ send_email_report() { if [ "$WEB_SYSTEM" = "apache2" ]; then apache2ctl configtest >> "$tmpfile" 2>&1 else - service $WEB_SYSTEM configtest >> "$tmpfile" 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$WEB_SYSTEM" "$tmpfile" + else + service $WEB_SYSTEM configtest >> "$tmpfile" 2>&1 + fi fi if [ "$1" == "DO_RESTART" ]; then service "$WEB_SYSTEM" restart >> "$tmpfile" 2>&1 @@ -74,9 +78,17 @@ if [ $WEB_SYSTEM = 'nginx' ]; then fi if [ "$DEBUG_MODE" = "true" ]; then echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1 - service $WEB_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$WEB_SYSTEM" + else + service $WEB_SYSTEM configtest >> /var/log/hestia/debug.log 2>&1 + fi else - service $WEB_SYSTEM configtest > /dev/null 2>&1 + if [ -f /etc/redhat-release ]; then + $BIN/v-check-service-config "$WEB_SYSTEM" /dev/null + else + service $WEB_SYSTEM configtest > /dev/null 2>&1 + fi fi if [ $? -ne 0 ]; then send_email_report @@ -93,6 +105,17 @@ elif [ $WEB_SYSTEM = 'apache2' ]; then send_email_report check_result "$E_RESTART" "$WEB_SYSTEM restart failed" fi +elif [ $WEB_SYSTEM = 'httpd' ]; then + if [ "$DEBUG_MODE" = "true" ]; then + echo "[ $date | $WEB_SYSTEM | WEB ]" >> /var/log/hestia/debug.log 2>&1 + $BIN/v-check-service-config "$WEB_SYSTEM" /var/log/hestia/debug.log + else + $BIN/v-check-service-config "$WEB_SYSTEM" /dev/null + fi + if [ $? -ne 0 ]; then + send_email_report + check_result "$E_RESTART" "$WEB_SYSTEM restart failed" + fi fi $BIN/v-restart-service "$WEB_SYSTEM" "$restart" diff --git a/func/domain.sh b/func/domain.sh index ddc0926..ef94b43 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -147,7 +147,11 @@ prepare_web_backend() { # Delete web backend delete_web_backend() { +if [ -f "/etc/redhat-release" ]; then + find -L /etc/opt/remi/ -name "$backend_type.conf" -exec rm -f {} \; +else find -L /etc/php/ -type f -name "$backend_type.conf" -exec rm -f {} \; +fi } # Prepare web aliases