How to setup bash script to monitor Nginx service in Linux.

linux

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

Copy Script from Github

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

 

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

View all posts by AmritMatti →

Leave a Reply

Your email address will not be published. Required fields are marked *