Posts

Showing posts from September, 2014

Script to monitor any service running or not

There are cases where we want to monitor running services in our servers and if in case they fails take a action according to that..

In the example script we are monitoring PHP, so if your monitoring any other service please adjust your at least "count"parameter accordingly..

Place the script in cron to check the required service..

#!/bin/bash #To count the no of process running count=$(ps -ef | grep -c php) #To show count no for testing echo $count #Comparing the count variable with min required by us if [ $count -lt 5 ]; then echo -e "\nThe php seems to be not running starting it..." #Auto starting the required service if not running, will differ according to your need killall php-fpm /etc/init.d/php-fpm start /etc/init.d/nginx restart #Sending a mail to desired user about the start of service with fetching hostname from AWS echo -e "The PHP was stopped somehow but now it has been restarted in `wget -q -O - http://169.254.169.254/latest/meta-data/publi…