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