migrate_mpm_event.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # This script migrates your apache2 installation form mod_prefork to mpm_event.
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Includes
  7. source $HESTIA/conf/hestia.conf
  8. # Check if apache2 is in use
  9. if [ "$WEB_SYSTEM" != "apache2" ]; then
  10. echo "Apache2 isn't installed on your system, canceling migration..." && exit 1
  11. fi
  12. # Check if PHP-FPM is instaled
  13. if [ "$WEB_BACKEND" != "php-fpm" ]; then
  14. echo "PHP-FPM not yet installed please run migrate_apache.sh first" && exit 1
  15. fi
  16. # Check if mod_event is already enabled
  17. if [ $(a2query -M) = 'event' ]; then
  18. echo "mod_event is already enabled, canceling migration..." && exit 1
  19. fi
  20. if ! apache2ctl configtest > /dev/null 2>&1; then
  21. echo "Apache2 configtest failed" && exit 1
  22. fi
  23. a2modules="php5.6 php7.0 php7.1 php7.2 php7.3 php7.4 ruid2 mpm_itk mpm_prefork"
  24. changed_a2modules=""
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. for module in $a2modules; do
  29. a2query -q -m "$module" || continue
  30. a2dismod -q "$module"
  31. changed_a2modules="${changed_a2modules} ${module}"
  32. done
  33. a2enmod --quiet mpm_event
  34. cp -f /usr/local/hestia/install/deb/apache2/hestia-event.conf /etc/apache2/conf.d/
  35. # Check if all went well
  36. if ! apache2ctl configtest > /dev/null 2>&1; then
  37. echo "Something went wrong, rolling back. Please try to migrate manually to mpm_event."
  38. a2dismod -q mpm_event
  39. for module in $changed_a2modules; do
  40. a2enmod "$module"
  41. done
  42. rm --force /etc/apache2/conf.d/hestia-event.conf
  43. exit 1
  44. fi
  45. # Validate if www.conf is existent and port 9000 is active
  46. if ! lsof -Pi :9000 -sTCP:LISTEN -t > /dev/null; then
  47. if [ $(ls /etc/php/7.3/fpm/pool.d/www.conf) ]; then
  48. # Replace listen port to 9000
  49. sed -i "s/listen = 127.0.0.1:.*/listen = 127.0.0.1:9000/g" /etc/php/7.3/fpm/pool.d/www.conf
  50. else
  51. # Copy www.conf file
  52. cp -f /usr/local/hestia/install/deb/php-fpm/www.conf /etc/php/7.3/fpm/pool.d/
  53. fi
  54. # Restart php7.3 fpm service.
  55. systemctl restart php7.3-fpm
  56. fi
  57. # Check again if port 9000 is now in use.
  58. if lsof -Pi :9000 -sTCP:LISTEN -t > /dev/null; then
  59. echo "mpm_event module was successfully activated."
  60. else
  61. echo "There went something wrong with your php-fpm configuration - port 9000 isnt active. Please check if webmail and phpmyadmin (if installed) are working properly."
  62. fi
  63. #----------------------------------------------------------#
  64. # Hestia #
  65. #----------------------------------------------------------#
  66. systemctl restart apache2