It’s really very tough job for every System Administrator to monitor and debug Linux System Performance problems every day. After being a Linux Administrator in IT industry, I came to know that how hard is to monitor and keep systems up and running. Apache is the main service one of them. For this reason, I have created some service monitoring bash scripts. This bash script is available under all flavors of Linux and can be useful to monitor Apache service.
Create a file apache-check.sh and put below content in that:
#!/bin/bash
UP=$(netstat -tulpn | grep :80 | grep apache2 | wc -l);
if [ “$UP” -ne 1 ];
then
sudo service apache2 start
else
echo “Webserver Is UP”;
fi
I am going to setup this script in cronjob for to run at every minute. So it will check Apache service at every minute and start the service if found it down.
NOTE: Please add this script in cronjob as root user.
To setup cronjob hit below command
crontab –e
and put below content at the end of file
* * * * * path_to_apache-check.sh
ALL! Done