Script to restart any service automatically

We can set the cron to restart the server when it was down or not running. You can use following script to detect and restart the httpd,ngnix,Serv-U or any other services.

1) Create the file vi /root/ and add the following code and save it.
You can replace the Serv-U with any your service like httpd or ngnix

# Restart command of your services
RESTART="/etc/init.d/Serv-U restart"
#Path to pgrep command

# Daemon name of your services

# find pid of serivces

if [ $? -ne 0 ] # if service not running
# restart Service

2) chdmo 755 /root/

3) Set Cron to check every 3 minutes  vi /var/spool/cron/root

*/3 * * * * sh /root/

4) Done

Script to restart any service automatically, Hostripples Web Hosting
Vishwajit Kale
Vishwajit Kale blazed onto the digital marketing scene back in 2015 and is the digital marketing strategist of Hostripples, a company that aims to provide affordable web hosting solutions. Vishwajit is experienced in digital and content marketing along with SEO. He's fond of writing technology blogs, traveling and reading.
Subscribe Now to stay updated.

Please fill in your email address to get most latest updates.