migrate_mpm_event.sh 2.2 KB

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