From be9310ae7e40016fa805022ae2314c97d0e4fc55 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Thu, 21 Nov 2024 14:56:24 -0800 Subject: [PATCH] add vhost-php-fpm-socket-helper.service, recreates /run/php/php-fpm-vpanel.sock on reboot --- install.sh | 5 ++++ sbin/vhost-php-fpm-socket-helper.sh | 32 +++++++++++++++++++++ systemd/vhost-php-fpm-socket-helper.service | 12 ++++++++ 3 files changed, 49 insertions(+) create mode 100755 sbin/vhost-php-fpm-socket-helper.sh create mode 100644 systemd/vhost-php-fpm-socket-helper.service diff --git a/install.sh b/install.sh index effeed7..5310036 100755 --- a/install.sh +++ b/install.sh @@ -3,6 +3,10 @@ apt-get install -y sudo useradd --no-create-home --home-dir /srv/www/html/panel --shell /usr/sbin/nologin --system --user-group vpanel cp bin/vpanel-verify-access.sh /usr/local/bin/ chmod 755 /usr/local/bin/vpanel-verify-access.sh +cp sbin/vhost-php-fpm-socket-helper.sh /usr/local/sbin +chmod 755 /usr/local/sbin/vhost-php-fpm-socket-helper.sh +cp systemd/vhost-php-fpm-socket-helper.service /usr/local/lib/systemd/system/ +chmod 644 /usr/local/lib/systemd/system/vhost-php-fpm-socket-helper.service # set PHP version PHP_MAJOR_VERSION=`php -r "echo PHP_MAJOR_VERSION;"` PHP_MINOR_VERSION=`php -r "echo PHP_MINOR_VERSION;"` @@ -19,6 +23,7 @@ update-alternatives --install /run/php/php-fpm-vpanel.sock php-fpm-vpanel.sock / a2enconf vpanel service php$phpVersion-fpm restart service apache2 restart +systemctl enable vhost-php-fpm-socket-helper.service cp -a panel /srv/www/html/ mkdir /srv/www/html/panel/tmp git clone https://github.com/bcosca/fatfree-core.git /srv/www/html/panel/f3 diff --git a/sbin/vhost-php-fpm-socket-helper.sh b/sbin/vhost-php-fpm-socket-helper.sh new file mode 100755 index 0000000..6c2be7e --- /dev/null +++ b/sbin/vhost-php-fpm-socket-helper.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# vhost-stack +# https://git.stack-source.com/msb/vhost-stack +# Copyright (c) 2024 Matthew Saunders Brown +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# check for missing /run/php/php-fpm-vpanel.sock link +if [[ ! -L /run/php/php-fpm-vpanel.sock ]]; then + # check for existing alternatives and use that if it's set + if [[ -L /etc/alternatives/php-fpm-vpanel.sock ]]; then + SOCKET=`readlink /etc/alternatives/php-fpm-vpanel.sock` + if [[ -S $SOCKET ]]; then + /usr/bin/update-alternatives --quiet --set php-fpm-vpanel.sock $SOCKET + else + echo "ERROR: Socket $SOCKET does not exists" + exit 1 + fi + else + # alternatives not set for php-fpm-vpanel.sock, get current php-cli version and use that + PHP_MAJOR_VERSION=`php -r "echo PHP_MAJOR_VERSION;"` + PHP_MINOR_VERSION=`php -r "echo PHP_MINOR_VERSION;"` + SOCKET=/run/php/php$PHP_MAJOR_VERSION.$PHP_MINOR_VERSION-fpm-vpanel.sock + PRIORITY=$PHP_MAJOR_VERSION$PHP_MINOR_VERSION + if [[ -S $SOCKET ]]; then + update-alternatives --quiet --install /run/php/php-fpm-vpanel.sock php-fpm-vpanel.sock $SOCKET $PRIORITY + else + echo "ERROR: Socket $SOCKET does not exists" + exit 1 + fi + fi +fi diff --git a/systemd/vhost-php-fpm-socket-helper.service b/systemd/vhost-php-fpm-socket-helper.service new file mode 100644 index 0000000..0786fc2 --- /dev/null +++ b/systemd/vhost-php-fpm-socket-helper.service @@ -0,0 +1,12 @@ +[Unit] +After=network.target local-fs.target + +[Service] +Type=oneshot +# sleep to give time for php-fpm to start first +# testing showed 2 seconds enough, using 5 for exra buffer +ExecStartPre=sleep 5 +ExecStart=/usr/local/sbin/vhost-php-fpm-socket-helper.sh + +[Install] +WantedBy=multi-user.target