Page 1 of 1

Auto-restart for all PHP-FPM services

Posted: Sun Nov 24, 2024 3:33 pm
by myVesta
If OOM Killer kills FPM services, let's add an auto-restart mechanism:

Code: Select all

for php in $(/usr/local/vesta/bin/v-list-php-apache); do
    echo "- Applying auto-restart for PHP $php"
    mkdir -p /etc/systemd/system/php$php-fpm.service.d
    cat <<EOF >/etc/systemd/system/php$php-fpm.service.d/override.conf
[Unit]
StartLimitIntervalSec=0
StartLimitBurst=0

[Service]
Restart=always
RestartSec=5s
EOF
done
systemctl daemon-reload
Let's test:

Code: Select all

php='7.4'
kill -9 $(systemctl status php$php-fpm | grep 'Main PID' | awk '{print $3}')
sleep 1
echo "--- here it should be killed ---"
systemctl status php$php-fpm
sleep 7
echo ""
echo "--- here it should be auto-restarted [active (running)] ---"
systemctl status php$php-fpm