migrate_apache.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: enable multiphp
  3. #
  4. # This function enables php-fpm backend for standalone apache2 configurations.
  5. #----------------------------------------------------------#
  6. # Variable&Function #
  7. #----------------------------------------------------------#
  8. # Includes
  9. # shellcheck source=/usr/local/hestia/func/main.sh
  10. source $HESTIA/func/main.sh
  11. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  12. source $HESTIA/conf/hestia.conf
  13. #----------------------------------------------------------#
  14. # Verifications #
  15. #----------------------------------------------------------#
  16. if [ ! -z "$WEB_BACKEND" ]; then
  17. check_result $E_EXISTS "Web backend already enabled" > /dev/null
  18. fi
  19. if [ "$(multiphp_count)" -gt 1 ]; then
  20. check_result $E_EXISTS "Multiphp already enabled" > /dev/null
  21. fi
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. php_v="$(multiphp_default_version)"
  26. $BIN/v-add-web-php "$php_v"
  27. cp -f "${HESTIA_INSTALL_DIR}/php-fpm/www.conf" "/etc/php/${php_v}/fpm/pool.d/www.conf"
  28. systemctl start php${php_v}-fpm
  29. check_result $? "php${php_v}-fpm start failed"
  30. update-alternatives --set php /usr/bin/php${php_v}
  31. if [ ! -z "$WEB_SYSTEM" ]; then
  32. cp -rf "${HESTIA_INSTALL_DIR}/templates/web/$WEB_SYSTEM" "${WEBTPL}/"
  33. fi
  34. sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf $HESTIA/conf/defaults/hestia.conf
  35. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  36. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/defaults/hestia.conf
  37. for user in $($BIN/v-list-sys-users plain); do
  38. # Define user data and get suspended status
  39. USER_DATA=$HESTIA/data/users/$user
  40. SUSPENDED=$(get_user_value '$SUSPENDED')
  41. # Check if user is suspended
  42. if [ "$SUSPENDED" = "yes" ]; then
  43. suspended="yes"
  44. $BIN/v-unsuspend-user $user
  45. fi
  46. for domain in $($BIN/v-list-web-domains $user plain | cut -f1); do
  47. SUSPENDED_WEB=$(get_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED')
  48. # Check if web domain is suspended
  49. if [ "$SUSPENDED_WEB" = "yes" ]; then
  50. suspended_web="yes"
  51. $BIN/v-unsuspend-web-domain $user $domain
  52. fi
  53. echo "Processing domain: $domain"
  54. $BIN/v-change-web-domain-backend-tpl "$user" "$domain" "PHP-${php_v/\./_}" "no"
  55. $BIN/v-change-web-domain-tpl "$user" "$domain" "default" "no"
  56. # Suspend domain again, if it was suspended
  57. if [ "$suspended_web" = "yes" ]; then
  58. unset suspended_web
  59. $BIN/v-suspend-web-domain $user $domain
  60. fi
  61. done
  62. # Suspend user again, if he was suspended
  63. if [ "$suspended" = "yes" ]; then
  64. unset suspended
  65. $BIN/v-suspend-user $user
  66. fi
  67. done
  68. $BIN/v-update-web-templates "yes"
  69. # Restarting backend
  70. $BIN/v-restart-web-backend "yes"
  71. check_result $? "Backend restart" > /dev/null 2>&1
  72. #----------------------------------------------------------#
  73. # Hestia #
  74. #----------------------------------------------------------#
  75. # Logging
  76. log_history "Enabled multiphp $version" '' 'admin'
  77. log_event "$OK" "$ARGUMENTS"
  78. exit