Linux - Check Apache and MySQL Are Running, Otherwise Start Them
The file is also reachable through this link: lamp-guarddog
#!/bin/sh
# Check whether Apache or/and Mysql server are down. If so, it starts them.
SERVICE_HTTP=’/usr/sbin/httpd’
SERVICE_MYSQL=’/usr/libexec/mysqld’
ADMIN_EMAIL=’danieleocchipinti.it@gmail.com’
if ps ax | grep -v grep | grep $SERVICE_HTTP > /dev/null
then
#echo “$SERVICE_HTTP is running”
a=0
else
echo “$SERVICE_HTTP is not running”
echo “$SERVICE_HTTP is not running!” | mail -s “$SERVICE_HTTP down” $ADMIN_EMAIL
service httpd start
fi
if ps ax | grep -v grep | grep $SERVICE_MYSQL > /dev/null
then
#echo “$SERVICE_MYSQL is running”
a=0
else
echo “$SERVICE_MYSQL is not running”
echo “$SERVICE_MYSQL is not running!” | mail -s “$SERVICE_MYSQL down” $ADMIN_EMAIL
service mysqld start
fi