Просмотр исходного кода

Improve update speed due optimasation (#2697)

* Change order

* Improve update script

* Improve general speed

* Undo changes

* Don't restart all php version if you only need reload 1 or 2

With more php version active restarting takes a alot of time:
By checking what php version need to get an update it will not restart the php version you don't need

* Fix typo

* Update v-delete-web-domain-backend

* Change order rebuild an update config value

* Make sure to reset the correct version when default it used
Jaap Marcus 3 лет назад
Родитель
Сommit
a180d28273

+ 1 - 1
bin/v-add-web-domain-backend

@@ -84,7 +84,7 @@ fi
 #----------------------------------------------------------#
 
 # Restart backend server
-$BIN/v-restart-web-backend "$restart"
+$BIN/v-restart-web-backend "$restart" "$backend_version"
 check_result $? "Web backend restart failed" >/dev/null
 
 # Logging

+ 1 - 1
bin/v-change-mail-domain-rate-limit

@@ -62,9 +62,9 @@ if [[ "$rate" = "system" ]]; then
     rate=''
 fi
 
-$HESTIA/bin/v-rebuild-mail-domain "$user" "$domain"
 # Update quota
 update_object_value "mail" 'DOMAIN' "$domain" '$RATE_LIMIT' "$rate"
+$HESTIA/bin/v-rebuild-mail-domain "$user" "$domain"
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Mail" "Mail domain rate limit has changed ($rate)"

+ 12 - 1
bin/v-change-web-domain-backend-tpl

@@ -165,7 +165,18 @@ fi
 $BIN/v-restart-web "$restart"
 check_result $? "Web restart failed" >/dev/null
 
-$BIN/v-restart-web-backend "$restart"
+# Detect prev version
+if [[ $BACKEND =~ ^.*PHP-([0-9])\_([0-9])$ ]]; then
+    version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
+else
+    version=$(multiphp_default_version)
+fi
+
+$BIN/v-restart-web-backend "$restart" "$version"
+if [ "$version" != "$backend_version" ]; then
+    $BIN/v-restart-web-backend "$restart" "$backend_version"
+fi
+
 check_result $? "Web backend restart failed" >/dev/null
 
 # Logging

+ 5 - 4
bin/v-change-web-domain-docroot

@@ -26,6 +26,7 @@ domain=$2
 export target_domain=$3
 export target_directory=$4
 export php=$5
+restart=$6
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -44,15 +45,15 @@ format_domain
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-check_args '2' "$#" 'USER DOMAIN TARGET_DOMAIN [DIRECTORY]'
+check_args '2' "$#" 'USER DOMAIN [TARGET_DOMAIN] [DIRECTORY] [PHP-DOCROOT] [RESTART]'
 is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
 # Check to ensure that target domain is valid if we're
 # not setting the docroot value back to defaults
 if [ "$target_domain" != "default" ]; then
-    is_format_valid 'user' 'domain' 'target_domain'
+    is_format_valid 'user' 'domain' 'target_domain' 'restart'
     is_object_valid 'web' 'DOMAIN' "$target_domain"
 else
-    is_format_valid 'user' 'domain'
+    is_format_valid 'user' 'domain' 'restart'
 fi
 is_object_valid 'user' 'USER' "$user" "$user"
 is_object_unsuspended 'user' 'USER' "$user"
@@ -121,7 +122,7 @@ fi
 #----------------------------------------------------------#
 
 # Rebuild domain configuration
-$BIN/v-rebuild-web-domain "$user" "$domain"
+$BIN/v-rebuild-web-domain "$user" "$domain" "$restart"
 
 # Logging
 if [ "$target_domain" = "default" ]; then

+ 11 - 2
bin/v-delete-web-domain

@@ -58,6 +58,8 @@ check_hestia_demo_mode
 get_domain_values 'web'
 local_ip=$(get_real_ip "$IP")
 
+
+
 # Deleting ftp users
 if [ -n "$FTP_USER" ]; then
     for ftp_user in ${FTP_USER//:/ }; do
@@ -138,8 +140,15 @@ if [ -n "$SUSPENDED" ]; then
     fi
 fi
 
-# Restarting web server
-$BIN/v-restart-web "$restart"
+# Detect php version
+
+if [[ $BACKEND =~ ^.*PHP-([0-9])\_([0-9])$ ]]; then
+    version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
+else
+    version=$(multiphp_default_version)
+fi
+# Restarting backend server
+$BIN/v-restart-web-backend "$restart" "$version"
 check_result $? "Web restart failed" >/dev/null
 
 # Restarting proxy server

+ 12 - 1
bin/v-delete-web-domain-backend

@@ -49,6 +49,10 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+get_domain_values 'web'
+BACKEND="$template"
+
+
 # Defining pool directory
 pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
 if [ ! -e "$pool" ]; then
@@ -77,8 +81,15 @@ delete_web_backend
 #                       Hestia                             #
 #----------------------------------------------------------#
 
+
+# Detect prev version
+if [[ $BACKEND =~ ^.*PHP-([0-9])\_([0-9])$ ]]; then
+    version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
+else
+    version=$(multiphp_default_version)
+fi
 # Restarting backend server
-$BIN/v-restart-web-backend "$restart"
+$BIN/v-restart-web-backend "$restart" "$version"
 check_result $? "Backend restart failed" >/dev/null
 
 # Logging

+ 23 - 9
bin/v-restart-web-backend

@@ -6,6 +6,10 @@
 #
 # This function reloads backend server configuration.
 
+restart=$1
+# For backward compatibility might change in the feature
+version=$2
+
 #----------------------------------------------------------#
 #                Variables & Functions                     #
 #----------------------------------------------------------#
@@ -47,20 +51,30 @@ if [ "$1" = 'scheduled' ] || [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; th
 fi
 
 tmpfile=$(mktemp)
-# Substitute php-fpm service name formats
-for version in $($BIN/v-list-sys-php plain); do
-    v_php="php$version-fpm"
-    if [ ! -f "/etc/php/${version}/fpm/pool.d/dummy.conf" ]; then
-        cp -f "$HESTIA_INSTALL_DIR/php-fpm/dummy.conf" "/etc/php/${version}/fpm/pool.d/"
-        sed -i "s/9999/99${version//.}/g" "/etc/php/${version}/fpm/pool.d/dummy.conf"
-    fi
 
-    $BIN/v-restart-service "$v_php" "$1" >> $tmpfile 2>&1
+if [ -z "$version" ]; then
+    # Substitute php-fpm service name formats
+    for version in $($BIN/v-list-sys-php plain); do
+        v_php="php$version-fpm"
+        if [ ! -f "/etc/php/${version}/fpm/pool.d/dummy.conf" ]; then
+            cp -f "$HESTIA_INSTALL_DIR/php-fpm/dummy.conf" "/etc/php/${version}/fpm/pool.d/"
+            sed -i "s/9999/99${version//.}/g" "/etc/php/${version}/fpm/pool.d/dummy.conf"
+        fi
+    
+        $BIN/v-restart-service "$v_php" "$restart" 
+        if [ $? -ne 0 ]; then
+            send_email_report
+            check_result "$E_RESTART" "$v_php restart failed"
+        fi
+    done
+else
+    v_php="php$version-fpm"
+    $BIN/v-restart-service "$v_php" "$restart" 
     if [ $? -ne 0 ]; then
         send_email_report
         check_result "$E_RESTART" "$v_php restart failed"
     fi
-done
+fi
 
 # Update restart queue
 if [ -e "$HESTIA/data/queue/restart.pipe" ]; then

+ 17 - 5
func/syshealth.sh

@@ -464,8 +464,7 @@ function syshealth_repair_system_config() {
         $BIN/v-change-sys-config-value "POLICY_CSRF_STRICTNESS" "1"
     fi
     
-    mv $HESTIA/conf/hestia.conf $HESTIA/conf/hestia.old.conf
-    touch $HESTIA/conf/hestia.conf 
+    touch $HESTIA/conf/hestia.conf.new
     while IFS='= ' read -r lhs rhs
       do
           if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
@@ -473,10 +472,23 @@ function syshealth_repair_system_config() {
               rhs="${rhs%%*( )}"   # Del trailing spaces
               rhs="${rhs%\'*}"     # Del opening string quotes
               rhs="${rhs#\'*}"     # Del closing string quotes
-              $BIN/v-change-sys-config-value "$lhs" "$rhs"
+              
           fi
-      done < $HESTIA/conf/hestia.old.conf
-      rm $HESTIA/conf/hestia.old.conf
+          check_ckey=$(grep "^$lhs='" "$HESTIA/conf/hestia.conf.new")
+            if [ -z "$check_ckey" ]; then
+                echo "$lhs='$rhs'" >> "$HESTIA/conf/hestia.conf.new"
+            else
+                sed -i "s|^$lhs=.*|$lhs='$rhs'|g" "$HESTIA/conf/hestia.conf.new"
+            fi
+      done < $HESTIA/conf/hestia.conf
+      
+      cmp --silent $HESTIA/conf/hestia.conf $HESTIA/conf/hestia.conf.new
+      if [ $? -ne 0 ]; then 
+        echo "[ ! ] Duplicated keys found repair config"
+        rm  $HESTIA/conf/hestia.conf
+        cp $HESTIA/conf/hestia.conf.new $HESTIA/conf/hestia.conf
+        rm $HESTIA/conf/hestia.conf.new 
+      fi 
 }
 
 # Repair System Cron Jobs

+ 1 - 0
func/upgrade.sh

@@ -380,6 +380,7 @@ upgrade_init_logging() {
 }
 
 upgrade_start_backup() {
+    echo "============================================================================="
     echo "[ * ] Backing up existing templates and configuration files..."
     if [ "$DEBUG_MODE" = "true" ]; then
         echo "      - Packages"

+ 5 - 5
src/deb/hestia/postinst

@@ -51,14 +51,14 @@ fi
 upgrade_welcome_message_log >> $LOG
 upgrade_welcome_message
 
-# Perform upgrade health check and refresh configuration before upgrading
-upgrade_health_check | tee -a $LOG
-upgrade_replace_default_config
-upgrade_refresh_config
-
 # Back up existing configuration files and templates
 upgrade_start_backup | tee -a $LOG
 
+# Perform upgrade health check and refresh configuration before upgrading
+upgrade_health_check | tee -a $LOG
+upgrade_replace_default_config | tee -a $LOG
+upgrade_refresh_config | tee -a $LOG
+
 # Execute version-specific upgrade scripts
 upgrade_start_routine | tee -a $LOG