From e826a68bd3ddc10d1185ee93456f44c27f9b753e Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Mon, 8 Apr 2024 22:09:24 +0300 Subject: [PATCH] Fixes for php-fpm service --- bin/v-add-web-php | 6 +++ bin/v-oneshot-service | 39 ++++++++++++++++++++ bin/v-restart-web-backend | 28 +++++++++++--- func/domain.sh | 5 ++- func/main.sh | 12 +++++- install/hst-install-rhel.sh | 8 ++++ install/rpm/oneshot/hestiacp-prepare.service | 11 ++++++ 7 files changed, 101 insertions(+), 8 deletions(-) create mode 100755 bin/v-oneshot-service create mode 100644 install/rpm/oneshot/hestiacp-prepare.service diff --git a/bin/v-add-web-php b/bin/v-add-web-php index bba1d77..154d72d 100755 --- a/bin/v-add-web-php +++ b/bin/v-add-web-php @@ -21,6 +21,12 @@ source $HESTIA/func/main.sh # load config file source_conf "$HESTIA/conf/hestia.conf" source_conf "$HESTIA/install/upgrade/upgrade.conf" + +if [ -f /etc/redhat-release ]; then + for elem in "${!multiphp_v[@]}"; do + multiphp_v[$elem]=$(convert_dot_version_to_non_dot "${multiphp_v[$elem]}") + done +fi #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# diff --git a/bin/v-oneshot-service b/bin/v-oneshot-service new file mode 100755 index 0000000..6d2805a --- /dev/null +++ b/bin/v-oneshot-service @@ -0,0 +1,39 @@ +#!/bin/bash +# info: prepare actions befor whole system will start +# options: NONE +# +# example: v-oneshot-service +# +# This function prepares dir structure for such things +# wich deleted on system shoutdown, run as root only + +# Includes +# shellcheck source=/etc/hestiacp/hestia.conf +source /etc/hestiacp/hestia.conf +# shellcheck source=/usr/local/hestia/func/main.sh +source $HESTIA/func/main.sh +# load config file +source_conf "$HESTIA/conf/hestia.conf" + +# Checking root permissions +if [ "$(id -u)" != '0' ]; then + echo "Error: Script can be run executed only by root" + exit 10 +fi + +php_DIR="/run/php" +#make php directory in /var/run/directory for php-fpm +if [ -f /etc/redhat-release ]; then + user_apache=$(cat $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl | grep listen.group | cut -d= -f2 | xargs) + if [ -n "$user_apache" ]; then + if grep "$user_apache" /etc/passwd; then + if grep "$user_apache" /etc/group; then + if [ ! -e "$php_DIR" ]; then + mkdir "$php_DIR" + chmod 755 "$php_DIR" + chown "$user_apache":"$user_apache" "$php_DIR" + fi + fi + fi + fi +fi \ No newline at end of file diff --git a/bin/v-restart-web-backend b/bin/v-restart-web-backend index e3437bc..7d79c48 100755 --- a/bin/v-restart-web-backend +++ b/bin/v-restart-web-backend @@ -9,6 +9,9 @@ restart=$1 # For backward compatibility might change in the feature version=$2 +if [ -f "/etc/redhat-release" ]; then + version="${version//./}" +fi #----------------------------------------------------------# # Variables & Functions # @@ -55,10 +58,21 @@ tmpfile=$(mktemp) if [ -z "$version" ]; then # Substitute php-fpm service name formats for version in $($BIN/v-list-sys-php plain); do - v_php="php$version-fpm" - if [ ! -f "/etc/php/${version}/fpm/pool.d/dummy.conf" ]; then - cp -f "$HESTIA_INSTALL_DIR/php-fpm/dummy.conf" "/etc/php/${version}/fpm/pool.d/" - sed -i "s/9999/99${version//./}/g" "/etc/php/${version}/fpm/pool.d/dummy.conf" + if [ -f /etc/redhat-release ]; then + v_php="php$version-php-fpm" + else + v_php="php$version-fpm" + fi + if [ -f /etc/redhat-release ]; then + if [ ! -f "/etc/opt/remi/php${version}/php-fpm.d/dummy.conf" ]; then + cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/opt/remi/php${version}/php-fpm.d/ + sed -i "s/9999/99$v_tpl/g" /etc/opt/remi/php${version}/php-fpm.d/dummy.conf + fi + else + if [ ! -f "/etc/php/${version}/fpm/pool.d/dummy.conf" ]; then + cp -f "$HESTIA_INSTALL_DIR/php-fpm/dummy.conf" "/etc/php/${version}/fpm/pool.d/" + sed -i "s/9999/99${version//./}/g" "/etc/php/${version}/fpm/pool.d/dummy.conf" + fi fi $BIN/v-restart-service "$v_php" "$restart" @@ -68,7 +82,11 @@ if [ -z "$version" ]; then fi done else - v_php="php$version-fpm" + if [ -f /etc/redhat-release ]; then + v_php="php$version-php-fpm" + else + v_php="php$version-fpm" + fi $BIN/v-restart-service "$v_php" "$restart" if [ $? -ne 0 ]; then send_email_report diff --git a/func/domain.sh b/func/domain.sh index 4263dce..e92b671 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -103,7 +103,7 @@ prepare_web_backend() { local backend_template=${1:-$template} if [ -f "/etc/redhat-release" ]; then - pool=$(find -L /etc/opt/remi/php80/ -name "$domain.conf" -exec dirname {} \;) + pool=$(find -L /etc/opt/remi/php80/ -name "$domain.conf" -exec dirname {} \; 2>/dev/null) else pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;) fi @@ -121,7 +121,8 @@ prepare_web_backend() { backend_version=$(multiphp_default_version) if [ -z "$pool" ] || [ -z "$BACKEND" ]; then if [ -f "/etc/redhat-release" ]; then - pool=$(find -L /etc/opt/remi/php80 -type d \( -name "pool.d" -o -name "*fpm.d" \)) + m_backend_version="${backend_version//./}" + pool=$(find -L /etc/opt/remi/php$m_backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \)) else pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \)) fi diff --git a/func/main.sh b/func/main.sh index 229fdc7..8c7a248 100644 --- a/func/main.sh +++ b/func/main.sh @@ -14,7 +14,11 @@ BACKUP_DISK_LIMIT=95 BACKUP_LA_LIMIT=$(cat /proc/cpuinfo | grep processor | wc -l) RRD_STEP=300 BIN=$HESTIA/bin -HESTIA_INSTALL_DIR="$HESTIA/install/deb" +if [ -f /etc/redhat-release ]; then + HESTIA_INSTALL_DIR="$HESTIA/install/rpm" +else + HESTIA_INSTALL_DIR="$HESTIA/install/deb" +fi HESTIA_COMMON_DIR="$HESTIA/install/common" HESTIA_BACKUP="/root/hst_backups/$(date +%d%m%Y%H%M)" HESTIA_PHP="$HESTIA/php/bin/php" @@ -1712,3 +1716,9 @@ search_command_arg_position() { echo "$position" } + +# Convert version X.X to XX +convert_dot_version_to_non_dot() { + version="$1" + echo "${version//./}" +} diff --git a/install/hst-install-rhel.sh b/install/hst-install-rhel.sh index 88208ce..5fa74e5 100755 --- a/install/hst-install-rhel.sh +++ b/install/hst-install-rhel.sh @@ -1897,6 +1897,14 @@ if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ]; then systemctl restart httpd fi +#install oneshot service for hestia +echo "[ * ] Configuring One Shot Service..." +$HESTIA/bin/v-oneshot-service +if [ ! -e /etc/systemd/system/hestiacp-prepare.service ]; then + cp -f $HESTIA_INSTALL_DIR/oneshot/hestiacp-prepare.service /etc/systemd/system/ + systemctl enable hestiacp-prepare.service --now +fi + # Adding default domain $HESTIA/bin/v-add-web-domain admin $servername $ip check_result $? "can't create $servername domain" diff --git a/install/rpm/oneshot/hestiacp-prepare.service b/install/rpm/oneshot/hestiacp-prepare.service new file mode 100644 index 0000000..d5321ad --- /dev/null +++ b/install/rpm/oneshot/hestiacp-prepare.service @@ -0,0 +1,11 @@ +[Unit] +Description=Prepare some actions on system boot for HestiaCP rpm +Before=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/hestia/bin/v-oneshot-service + +[Install] +WantedBy=multi-user.target \ No newline at end of file