Monitor & Restart HTTPD / NGINX conf & more service

Monitor service up/down & auto restart //httpd (apache)
vim /root/apacherestart.sh
#!/bin/bash
PGREP="/usr/bin/pgrep"
CHKSERVICE="httpd"
$PGREP ${CHKSERVICE}
if [ $? -ne 0 ]
then
# printf $?
/etc/init.d/httpd restart
date >> /root/apacherestart.log
fi
chmod 777 & set crontab
*/5 * * * * /root/apacherestart.sh >/dev/null 2>&1

Monitor service process & auto restart //httpd (apache)
vim /usr/local/auto/auto_restart.sh
#!/bin/bash
check=`ps aux | grep 'httpd' | awk '{print $6;}' | awk '{avg += $1;} END {printf avg;}'`
#printf $check
if [ $check -gt 1000000 ]
then
/etc/init.d/httpd restart
# /etc/init.d/nginx restart
# /etc/init.d/php-fpm56 restart
# /etc/init.d/php-fpm70 restart
date >> /usr/local/auto/auto_restart.log
fi
chmod 777 & set crontab
*/5 * * * * /usr/local/auto/auto_restart.sh >/dev/null 2>&1

Monitor nginx.conf from ithemes security wordpress plugin & restart service
vim /root/ithemesec_nginx_monitor_mbth.sh
#!/bin/bash

LTIMEE=`stat -c %Z /home/user/web/domain.com/public_html/nginx.conf`

while sleep 3
do
ATIMEE=`stat -c %Z /home/user/web/domain.com/public_html/nginx.conf`

if [ "$ATIMEE" != "$LTIMEE" ]
then
# /etc/init.d/nginx reload >/dev/null
nginx -s reload
LTIMEE=$ATIMEE
date >> /root/ithemesec_nginx_monitor_mbth.log
fi
done
chmod 777 & set startup in /etc/rc.local
bash /root/ithemesec_nginx_monitor_mbth.sh &
check .sh
vim /root/ithemesec_nginx_monitor_mbth_chk.sh
#!/bin/bash
check=`ps aux | grep '[m]bth' | awk '$11=="bash" {print $11;}'`
#printf $check
if [ "$check" != "bash" ]
then
bash /root/ithemesec_nginx_monitor_mbth.sh &
date >> /root/ithemesec_nginx_monitor_mbth_chk.log
fi
chmod 777 & set crontab
*/5 * * * * /bin/sh /root/ithemesec_nginx_monitor_mbth_chk.sh

Blog | , ,
Line it!