Monitor PHP-FPM and Nginx - Script for low memory environments / Alix
-
Hi.
In Alix 2d3, which some days on, the pfsense get "bad gateway" message in browser. In console i get "swap out, kill pid" message.
So, i suggest a script to solve this. Works for me.Install Cron package from webgui pfsense.
- First line is the file and above the content.
/usr/local/etc/php-fpm-test.sh
#!/bin/sh
SERVICE=php-fpm
if P=$(pgrep $SERVICE)
then
#echo "$SERVICE is running, PID is $P"
exit
else
/etc/rc.php-fpm_restart
fi/usr/local/etc/nginx-test.sh
#!/bin/sh
SERVICE=nginx
if P=$(pgrep $SERVICE)
then
#echo "$SERVICE is running, PID is $P"
exit
else
/etc/rc.restart_webgui
fiOBS: If you want see if process is ok, just remove the # from echo line.
commands:
chmod 655 /usr/local/etc/php-fpm-test.sh
chmod 655 /usr/local/etc/nginx-test.sh
chmod +x /usr/local/etc/php-fpm-test.sh
chmod +x /usr/local/etc/nginx-test.shIn Webgui -> Services -> Cron, insert:
*/1 * * * * root /usr/local/etc/php-fpm-test.sh
*/1 * * * * root /usr/local/etc/nginx-test.shEach minute, the cron will execute the script.
You can verify killing the php-fpm, nginx or both.Service_watch not display this services and in very low memory environments, create many child process, what is not very interested (usually idle is in 0% in busy environment) and depends on php (witch depends of more and more memory).