From c4646bd8e81bac813328aa94754f4a37acdac0db Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Sat, 4 May 2024 22:15:25 +0300 Subject: [PATCH] Make service configuring correct for rpm --- bin/v-list-sys-clamd-config | 5 ++- bin/v-list-sys-php | 23 ++++++++---- bin/v-list-sys-php-config | 12 +++++- bin/v-list-sys-services | 54 ++++++++++++++++++++------- bin/v-oneshot-service | 10 ++--- bin/v-restart-service | 4 ++ install/hst-install-rhel.sh | 2 +- src/rpm/php/hestia-php.service | 1 + web/list/server/index.php | 4 ++ web/templates/pages/list_services.php | 5 +++ 10 files changed, 89 insertions(+), 31 deletions(-) diff --git a/bin/v-list-sys-clamd-config b/bin/v-list-sys-clamd-config index 4683e43..c54e644 100755 --- a/bin/v-list-sys-clamd-config +++ b/bin/v-list-sys-clamd-config @@ -58,7 +58,10 @@ else config_path='/etc/clamd.conf' fi if [ -e '/etc/clamd.d/clamd.conf' ]; then - config_path='/etc/clamav/clamd.conf' + config_path='/etc/clamd.d/clamd.conf' + fi + if [ -e '/etc/clamd.d/daemon.conf' ]; then + config_path='/etc/clamd.d/daemon.conf' fi fi diff --git a/bin/v-list-sys-php b/bin/v-list-sys-php index 5f1ecab..c415a64 100755 --- a/bin/v-list-sys-php +++ b/bin/v-list-sys-php @@ -67,17 +67,24 @@ csv_list() { declare -a versions # List through /etc/php -if [ -n "$WEB_BACKEND" ]; then - for version in /etc/php/*/fpm; do - ver=$(echo "$version" | awk -F"/" '{ print $4 }') +if [ -f /etc/redhat-release ]; then + for version in /etc/opt/remi/php*/; do + ver=$(echo "$version" | awk -F"/" '{ print $5 }' | sed 's|php||') versions+=("$ver") done else - # Fix for modphp - for version in /etc/php/*/cli; do - ver=$(echo "$version" | awk -F"/" '{ print $4 }') - versions+=("$ver") - done + if [ -n "$WEB_BACKEND" ]; then + for version in /etc/php/*/fpm; do + ver=$(echo "$version" | awk -F"/" '{ print $4 }') + versions+=("$ver") + done + else + # Fix for modphp + for version in /etc/php/*/cli; do + ver=$(echo "$version" | awk -F"/" '{ print $4 }') + versions+=("$ver") + done + fi fi # Listing data case $format in diff --git a/bin/v-list-sys-php-config b/bin/v-list-sys-php-config index b78e774..2c07df7 100755 --- a/bin/v-list-sys-php-config +++ b/bin/v-list-sys-php-config @@ -63,10 +63,18 @@ csv_list() { #----------------------------------------------------------# # Defining config path -config_path=$(find /etc/php* -name php.ini) +if [ -f /etc/redhat-release ]; then + config_path=$(find /etc/opt/remi/php* -name php.ini) +else + config_path=$(find /etc/php* -name php.ini) +fi config_count=$(echo "$config_path" | wc -l) if [ "$config_count" -gt 1 ]; then - multiphp_versions=$(ls -d /etc/php/*/fpm/pool.d 2> /dev/null | wc -l) + if [ -f /etc/redhat-release ]; then + multiphp_versions=$(ls -d /etc/opt/remi/php*/php-fpm.d 2> /dev/null | wc -l) + else + multiphp_versions=$(ls -d /etc/php/*/fpm/pool.d 2> /dev/null | wc -l) + fi if [ "$WEB_BACKEND" = 'php-fpm' ] || [ "$multiphp_versions" -gt 0 ]; then config_path=$(echo "$config_path" | grep fpm) else diff --git a/bin/v-list-sys-services b/bin/v-list-sys-services index 2ee0cdb..330695e 100755 --- a/bin/v-list-sys-services +++ b/bin/v-list-sys-services @@ -86,13 +86,23 @@ get_srv_state() { rtime="0" # Searching related pids - if [ -z $3 ]; then - pids=$(pidof $name | tr ' ' '|') + if [ -f /etc/redhat-release ] && [ "$name" = "php-fpm" ]; then + pids='' + for php_pid in $(pidof php-fpm); do + process_info=$(ps -p "$php_pid" -o args | tail -n1 | grep "$srv") + if [ -n "$process_info" ]; then + pids="${pids}|${php_pid}" + fi + done else - pids=$(pidof -x $name | tr ' ' '|') - fi - if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then - pids=$(pgrep $name | tr '\n' '|') + if [ -z $3 ]; then + pids=$(pidof $name | tr ' ' '|') + else + pids=$(pidof -x $name | tr ' ' '|') + fi + if [ -z "$pids" ] && [ "$name" != 'nginx' ]; then + pids=$(pgrep $name | tr '\n' '|') + fi fi # Prevent from an SSH false positive when there is a TTY or SFTP connection but service is down @@ -164,14 +174,25 @@ fi # Checking PHP intepreter if [ -n "$WEB_BACKEND" ] && [ "$WEB_BACKEND" != 'remote' ]; then - php_versions=$(ls /usr/sbin/php*fpm* | cut -d'/' -f4 | sed 's|php-fpm||') - for version in $php_versions; do - proc_name="php-fpm${version}" - service_name="php${version}-fpm" - get_srv_state "$proc_name" - data="$data\nNAME='$service_name' SYSTEM='php interpreter' STATE='$state'" - data="$data CPU='$cpu' MEM='$mem' RTIME='$rtime'" - done + if [ -f /etc/redhat-release ]; then + php_versions=$(ls /opt/remi/php*/root/sbin/php-fpm | cut -d'/' -f4 | sed 's|php||') + for version in $php_versions; do + proc_name="php-fpm" + service_name="php${version}" + get_srv_state "$proc_name" + data="$data\nNAME='$service_name-php-fpm' SYSTEM='php interpreter' STATE='$state'" + data="$data CPU='$cpu' MEM='$mem' RTIME='$rtime'" + done + else + php_versions=$(ls /usr/sbin/php*fpm* | cut -d'/' -f4 | sed 's|php-fpm||') + for version in $php_versions; do + proc_name="php-fpm${version}" + service_name="php${version}-fpm" + get_srv_state "$service_name" "$proc_name" + data="$data\nNAME='$service_name' SYSTEM='php interpreter' STATE='$state'" + data="$data CPU='$cpu' MEM='$mem' RTIME='$rtime'" + done + fi fi # Checking WEB Proxy @@ -210,6 +231,11 @@ if [ -n "$ANTIVIRUS_SYSTEM" ] && [ "$ANTIVIRUS_SYSTEM" != 'remote' ]; then if [ "$ANTIVIRUS_SYSTEM" == 'clamav' ]; then ANTIVIRUS_SYSTEM='clamd' fi + if [ -f /etc/redhat-release ]; then + if [ "$ANTIVIRUS_SYSTEM" == 'clamav-daemon' ]; then + ANTIVIRUS_SYSTEM='clamd' + fi + fi get_srv_state "$ANTIVIRUS_SYSTEM" else if [ "$ANTIVIRUS_SYSTEM" == 'clamav-daemon' ]; then diff --git a/bin/v-oneshot-service b/bin/v-oneshot-service index a1028e8..ab65dde 100755 --- a/bin/v-oneshot-service +++ b/bin/v-oneshot-service @@ -24,11 +24,11 @@ fi php_DIR="/run/php" #make php directory in /var/run/directory for php-fpm and for hestia-php 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 -q "$user_apache" /etc/passwd; then - if grep -q "$user_apache" /etc/group; then - if [ ! -e "$php_DIR" ]; then + if [ ! -e "$php_DIR" ]; 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 -q "$user_apache" /etc/passwd; then + if grep -q "$user_apache" /etc/group; then mkdir "$php_DIR" chmod 755 "$php_DIR" chown "$user_apache":"$user_apache" "$php_DIR" diff --git a/bin/v-restart-service b/bin/v-restart-service index a04b665..9898e5d 100755 --- a/bin/v-restart-service +++ b/bin/v-restart-service @@ -38,6 +38,10 @@ if [ "$DEBUG_MODE" = "true" ]; then log="/var/log/hestia/debug.log" fi +if [ "$service" = "cron" ] && [ -f /etc/redhat-release ]; then + service="crond" +fi + # Multi-instance service restart request handling if [ "$service" = "php-fpm" ]; then service_list='' diff --git a/install/hst-install-rhel.sh b/install/hst-install-rhel.sh index c0065af..5796707 100755 --- a/install/hst-install-rhel.sh +++ b/install/hst-install-rhel.sh @@ -1127,7 +1127,7 @@ if [ "$exim" = 'yes' ]; then fi # Cron daemon -write_config_value "CRON_SYSTEM" "cron" +write_config_value "CRON_SYSTEM" "crond" # Firewall stack if [ "$iptables" = 'yes' ]; then diff --git a/src/rpm/php/hestia-php.service b/src/rpm/php/hestia-php.service index 38a2fe5..4c30640 100644 --- a/src/rpm/php/hestia-php.service +++ b/src/rpm/php/hestia-php.service @@ -10,6 +10,7 @@ ExecStart=/usr/local/hestia/php/sbin/php-fpm --fpm-config /usr/local/hestia/php/ ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -TERM $MAINPID ExecStartPre=/bin/bash -c "/bin/systemctl set-environment HOSTNAME=$(/usr/bin/hostname)" +ExecStartPre=/bin/bash -c "[ -e /usr/local/hestia/bin/v-oneshot-service ] && /usr/local/hestia/bin/v-oneshot-service" Environment="HESTIA=/usr/local/hestia" [Install] diff --git a/web/list/server/index.php b/web/list/server/index.php index 651698f..42ecf52 100644 --- a/web/list/server/index.php +++ b/web/list/server/index.php @@ -125,7 +125,11 @@ unset($output); $phpfpm = []; foreach ($php as $version) { $phpfpm[] = "php" . $version . "-fpm"; + $phpfpm[] = "php" . $version . "-php-fpm"; } +$clamav_names = []; +$clamav_names[] = "clamav-daemon"; +$clamav_names[] = "clamd"; exec(HESTIA_CMD . "v-list-sys-services json", $output, $return_var); $data = json_decode(implode("", $output), true); diff --git a/web/templates/pages/list_services.php b/web/templates/pages/list_services.php index 25f292b..333ab7b 100644 --- a/web/templates/pages/list_services.php +++ b/web/templates/pages/list_services.php @@ -128,6 +128,11 @@ } else { $edit_url=$key; } + if (in_array($key, $clamav_names)){ + $edit_url="clamav-daemon"; + } else { + $edit_url=$key; + } $cpu = $data[$key]['CPU'] / 10; $cpu = number_format($cpu, 1);