Parcourir la source

Multiphp: ignore non php-fpm php versions when detecting the default php version

-After the release of php7.4, upgrading a system would partially install some php components but not php-fpm so it would break multiphp instalations for web domains which used the 'default' backend template
Robert Zollner il y a 6 ans
Parent
commit
cfd72dd1b6
2 fichiers modifiés avec 22 ajouts et 4 suppressions
  1. 1 1
      func/domain.sh
  2. 21 3
      func/main.sh

+ 1 - 1
func/domain.sh

@@ -94,7 +94,7 @@ prepare_web_backend() {
         backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
         backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
         pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
         pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
     else
     else
-        backend_version=$(php -r "echo (float)phpversion();")
+        backend_version=$(multiphp_default_version)
         if [ -z "$pool" ] || [ -z "$BACKEND" ]; then 
         if [ -z "$pool" ] || [ -z "$BACKEND" ]; then 
             pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
             pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
         fi
         fi

+ 21 - 3
func/main.sh

@@ -1072,15 +1072,33 @@ multiphp_count() {
 }
 }
 
 
 multiphp_versions() {
 multiphp_versions() {
+    local -a php_versions_list;
+    local php_ver;
     if [ "$(multiphp_count)" -gt 0 ] ; then
     if [ "$(multiphp_count)" -gt 0 ] ; then
-        for php_ver in $(ls /etc/php/); do
+        for php_ver in $(ls -v /etc/php/); do
             [ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
             [ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
-            echo -n "$php_ver "
+            php_versions_list+=($php_ver)
         done
         done
-        echo -en '\n'
+        echo "${php_versions_list[@]}"
     fi
     fi
 }
 }
 
 
+multiphp_default_version() {
+    # Get system wide default php version (set by update-alternatives)
+    local sys_phpversion=$(php -r "echo (float)phpversion();")
+
+    # Check if the system php also has php-fpm enabled, otherwise return
+    # the most recent php version which does have it installed.
+    if [ ! -d "/etc/php/$sys_phpversion/fpm/pool.d/" ]; then
+        local all_versions="$(multiphp_versions)"
+        if [ ! -z "$all_versions" ]; then
+            sys_phpversion="${all_versions##*\ }";
+        fi
+    fi
+
+    echo "$sys_phpversion"
+}
+
 # Run arbitrary cli commands with dropped privileges
 # Run arbitrary cli commands with dropped privileges
 # Note: setpriv --init-groups is not available on debian9 (util-linux 2.29.2)
 # Note: setpriv --init-groups is not available on debian9 (util-linux 2.29.2)
 # Input:
 # Input: