Auto-restart for all PHP-FPM services

Post Reply
User avatar
myVesta
Site Admin
Posts: 949
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

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

Tags:
Post Reply