Something Different In Linux

Home » Basic Linux » 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


Popular Posts

remove index.php fro

How to remove index.php from url in magento Ans : If you ...

PHP-Java bridge on p

  What is php-java bridge? The php-java bridge is the php ...

Set expiration for y

If you want to set the expiration to your site ...

Warning: Parameter 1

Error: Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a ...

domain pointing to e

If you domain uses external MX record and it is ...