migrate_apache.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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
  35. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  36. for user in $($BIN/v-list-sys-users plain); do
  37. # Define user data and get suspended status
  38. USER_DATA=$HESTIA/data/users/$user
  39. SUSPENDED=$(get_user_value '$SUSPENDED')
  40. # Check if user is suspended
  41. if [ "$SUSPENDED" = "yes" ]; then
  42. suspended="yes"
  43. $BIN/v-unsuspend-user $user
  44. fi
  45. for domain in $($BIN/v-list-web-domains $user plain | cut -f1); do
  46. SUSPENDED_WEB=$(get_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED')
  47. # Check if web domain is suspended
  48. if [ "$SUSPENDED_WEB" = "yes" ]; then
  49. suspended_web="yes"
  50. $BIN/v-unsuspend-web-domain $user $domain
  51. fi
  52. echo "Processing domain: $domain"
  53. $BIN/v-change-web-domain-backend-tpl "$user" "$domain" "PHP-${php_v/\./_}" "no"
  54. $BIN/v-change-web-domain-tpl "$user" "$domain" "default" "no"
  55. # Suspend domain again, if it was suspended
  56. if [ "$suspended_web" = "yes" ]; then
  57. unset suspended_web
  58. $BIN/v-suspend-web-domain $user $domain
  59. fi
  60. done
  61. # Suspend user again, if he was suspended
  62. if [ "$suspended" = "yes" ]; then
  63. unset suspended
  64. $BIN/v-suspend-user $user
  65. fi
  66. done
  67. $BIN/v-update-web-templates "yes"
  68. # Restarting backend
  69. $BIN/v-restart-web-backend "yes"
  70. check_result $? "Backend restart" > /dev/null 2>&1
  71. #----------------------------------------------------------#
  72. # Hestia #
  73. #----------------------------------------------------------#
  74. # Logging
  75. log_history "Enabled multiphp $version" '' 'admin'
  76. log_event "$OK" "$ARGUMENTS"
  77. exit