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

Add upgrade procedure from webtpl multiphp to multi php-fpm backend

ngx+fpm is supported by default, ngx+mphp and apache+mphp are migrated, apache with internal php is skipped
Robert Zollner 6 лет назад
Родитель
Сommit
9ae4cc5163

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

@@ -63,7 +63,7 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
         -e "s|%user%|$user|g"\
         -e "s|%domain%|$domain|g"\
         -e "s|%backend%|$backend_type|g"\
-        -e "s|%backend_version%|$version|g" > $pool/$backend_type.conf
+        -e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
 
 
 #----------------------------------------------------------#

+ 2 - 2
bin/v-add-web-php

@@ -33,7 +33,7 @@ if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
 fi
 
 # Check if php version already exists
-if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
+if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
     echo "Version already installed..."
     exit
 fi
@@ -100,7 +100,7 @@ cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
 sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
 
 # Install backend template
-cp -f $HESTIA_INSTALL_DIR/multiphp/php-fpm/default.tpl \
+cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
     $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 
 #----------------------------------------------------------#

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

@@ -70,7 +70,7 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
         -e "s|%domain%|$domain|g"\
         -e "s|%domain_idn%|$domain_idn|"\
         -e "s|%backend%|$backend_type|g"\
-        -e "s|%backend_version%|$version|g" > $pool/$backend_type.conf
+        -e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
 
 # Checking backend pool configuration
 if [ "$backend_type" = "$user" ]; then

+ 1 - 1
bin/v-delete-web-php

@@ -75,7 +75,7 @@ if [ -f "$php_fpm" ]; then
     echo "apt-get purge $mph"
 fi
 
-# Remove php templates
+# Remove backend template
 rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 
 #----------------------------------------------------------#

+ 7 - 2
bin/v-update-web-templates

@@ -27,6 +27,11 @@ if [ -d "${WEBTPL}" ]; then
     rm -rf "${WEBTPL}/unassigned" 2>/dev/null
 fi
 
+for php_ver in $(ls /etc/php/); do
+    [ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
+    cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl"  ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
+done
+
 for webtpl_folder in $(ls $HESTIA_INSTALL_DIR/templates/web/* -d 2>/dev/null | egrep -v '/(nginx)$' ); do
     cp -rf "${webtpl_folder}" "${WEBTPL}/"
 done
@@ -35,7 +40,7 @@ done
 
 # Update Multi-PHP templates
 php_versions=$(ls /etc/php/*/fpm -d 2>/dev/null | wc -l)
-if [ "$php_versions" -gt 1 ]; then
+if [ "$php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
     for v in $(ls /etc/php/); do
         if [ ! -d "/etc/php/$v/fpm/pool.d/" ]; then
             continue
@@ -53,7 +58,7 @@ if [ "$php_versions" -gt 1 ]; then
     fi
 fi
 
-if [ "$PROXY_SYSTEM" = 'nginx' ] || [ "$php_versions" -le 1 ]; then
+if [ "$PROXY_SYSTEM" = 'nginx' ] || [ "$WEB_BACKEND" = "php-fpm" ]; then
     cp -rf "${HESTIA_INSTALL_DIR}/templates/web/nginx" "${WEBTPL}/"
 fi
 

+ 7 - 5
func/domain.sh

@@ -84,20 +84,22 @@ is_web_alias_new() {
 
 # Prepare web backend
 prepare_web_backend() {
+    pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
     # Check if multiple-PHP installed
     regex="socket-(\d+)_(\d+)"
     if [[ $template =~ ^PHP-([0-9])\_([0-9])$ ]]; then
-        version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
-        pool=$(find -L /etc/php/$version -type d \( -name "pool.d" -o -name "*fpm.d" \))
+        backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
+        pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
     else
-        version=$(php -r "echo (float)phpversion();")
-        pool=$(find -L /etc/php/$version -type d \( -name "pool.d" -o -name "*fpm.d" \))
+        if [ -z "$pool" ] || [ -z "$BACKEND" ]; then 
+            backend_version=$(php -r "echo (float)phpversion();")
+            pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
+        fi
     fi
  
     if [ ! -e "$pool" ]; then
         check_result $E_NOTEXIST "php-fpm pool doesn't exist"
     fi
-
     backend_type="$domain"
     if [ "$WEB_BACKEND_POOL" = 'user' ]; then
         backend_type="$user"

+ 0 - 0
install/deb/multiphp/php-fpm/default.tpl → install/deb/php-fpm/multiphp.tpl


+ 124 - 1
install/upgrade/versions/latest.sh

@@ -54,4 +54,127 @@ fi
 # Remove errornous history.log file created by certain builds due to bug in v-restart-system
 if [ -e $HESTIA/data/users/history.log ]; then
     rm -f $HESTIA/data/users/history.log
-fi
+fi
+
+#
+# Migrate legacy multiphp to full php-fpm backend
+#
+# nginx+fpm (default)
+#   nothing to be done here,
+#   (Adding new php backends will make them available on edit/web)
+#
+# nginx+multiphp,
+# nginx+apache+multiphp,
+# apache+multiphp:
+#   Change Hestia WEB_BACKEND from null to php-fpm
+#   Create backend templates ex: PHP-7_3, PHP-5_6 (in $HESTIA/data/templates/web/php-fpm/)
+#   v-update-web-templates
+#   Loop trough all web domains
+#   If official multiphp tpl is used ex: PHP-72, then change backend tpl and set app web template to default
+#       ( old default.tpl backend maps to PHP-7_3 )
+#   If not, parse php version from tpl file , fallback to latest version,
+#   Copy all non-official tpls to php-fpm folder (as app web template includin bash script if present)
+#
+# a2 (non-fpm) or nginx+a2(non-fpm)
+# - Skipped
+#
+
+DEFAULT_BTPL="PHP-7_3"
+num_php_versions=$(ls -d /etc/php/*/fpm/pool.d 2>/dev/null |wc -l)
+echo $num_php_versions
+
+if [ "$num_php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
+    # Legacy multiphp
+
+    echo $num_php_versions
+    sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf
+    echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
+
+    for php_ver in $(ls /etc/php/); do
+        [ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
+        cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl"  ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
+    done
+
+    if [ "$WEB_SYSTEM" = 'nginx' ] ]; then
+        cp -rf "${HESTIA_INSTALL_DIR}/templates/web/nginx" "${WEBTPL}/"
+    fi
+
+    # Migrate domains
+    for user in $($BIN/v-list-sys-users plain); do
+        echo "Migrating legacy multiphp domains for user: $user"
+        for domain in $($BIN/v-list-web-domains $user plain |cut -f1); do
+            echo "Processing domain: $domain"
+            web_tpl="default"
+            backend_tpl="$DEFAULT_BTPL"
+            domain_tpl=$($BIN/v-list-web-domain $user $domain |grep "^TEMPLATE:" |awk '{print $2;}' );
+
+            if [ "$domain_tpl" = "PHP-56" ]; then
+                backend_tpl="PHP-5_6"
+            elif [ "$domain_tpl" = "PHP-70" ]; then
+                backend_tpl="PHP-7_0"
+            elif [ "$domain_tpl" = "PHP-71" ]; then
+                backend_tpl="PHP-7_1"
+            elif [ "$domain_tpl" = "PHP-72" ]; then
+                backend_tpl="PHP-7_2"
+            elif [ "$domain_tpl" = "PHP-73" ] || [ "$domain_tpl" = "default" ] || [ -z "$domain_tpl" ]; then
+                backend_tpl="PHP-7_3"
+            else
+                # Custom domain template used
+                echo "Domain is using a custom multiphp template (or non-multiphp one)"
+
+                web_tpl="$domain_tpl"
+                if [ -f "${WEBTPL}/$WEB_SYSTEM/php-fpm/$web_tpl.tpl" ]; then
+                    # php-fpm backend folder allready has a template with the same name
+                    web_tpl="custom-$domain_tpl"
+                fi
+
+                # Copy custom template to php-fpm backend folder
+                mkdir -p "$WEBTPL/$WEB_SYSTEM/php-fpm"
+                if [ -f "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" ]; then
+                    cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
+                fi
+                cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
+                cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.stpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
+
+
+                if [[ $(grep "unix:/" $WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl |egrep -v "^\s*#" |tail -n1) \
+                        =~ unix:\/run\/php\/php([0-9]+\.[0-9]+)-fpm.+\.sock ]]; then
+
+                    # Found a custom template that is based on official multiphp one
+                    backend_tpl="PHP-${BASH_REMATCH[1]/\./_}"
+                    echo "Custom multiphp template ($domain_tpl) compatible with backend: $backend_tpl"
+
+                    # Remove multiphp switching script
+                    rm -f "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
+
+                    # Replace hardcoded php-fpm socket path with tpl variable, ignoring commented lines
+                    sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
+                    sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
+                fi
+            fi
+
+            echo "Parsed config: oldTPL=$domain_tpl newTPL:$web_tpl newBackTPL:$backend_tpl"
+            $BIN/v-change-web-domain-tpl "$user" "$domain" "$web_tpl" "no"
+            $BIN/v-change-web-domain-backend-tpl "$user" "$domain" "$backend_tpl" "no"
+            echo -e "--done--\n"
+        done
+    done
+
+    # cleanup legacy multiphp templates
+    for php_ver in $(ls /etc/php/); do
+        [ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
+        echo "Remove legacy multiphp templates for: $php_ver"
+        [ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh" ]   && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh"
+        [ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl" ]  && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl"
+        [ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl"
+    done
+
+    # Remove default symlinks
+    [ -f "$WEBTPL/$WEB_SYSTEM/default.sh" ]   && rm "$WEBTPL/$WEB_SYSTEM/default.sh"
+    [ -f "$WEBTPL/$WEB_SYSTEM/default.tpl" ]  && rm "$WEBTPL/$WEB_SYSTEM/default.tpl"
+    [ -f "$WEBTPL/$WEB_SYSTEM/default.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.stpl"
+
+
+    $BIN/v-update-web-templates 'no'
+fi
+