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. Nginx 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 Nginx service.
Create a file nginx-check.sh and put below content in that:
#!/bin/bash
UP=$(netstat -tulpn | grep :80 | grep nginx | wc -l);
if [ “$UP” -ne 1 ];
then
sudo service nginx 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 Nginx 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_nginx-check.sh
ALL! Done