start apache2,mysql,nginx from shell script root crontab on ubuntu

in case Debian 3.2.68 distribution . all syntax will be working fine as per my live test.

cd /usr/local/vesta/bin

sudo nano apache-restart.sh

type following..

=========================================================================..

#!/bin/sh

ps auxw | grep apache2 | grep -v grep > /dev/null

if [ $? != 0 ]
then
        service apache2 start > /dev/null
fi
======================================================================================
save it as apache-restart.sh
sudo nano mysql-restart.sh
===================================================================================
#!/bin/bash
/usr/bin/mysqladmin ping| grep 'mysql is alive' > /dev/null 2>&1
if [ $? != 0 ]
then
 sudo service mysql restart
fi
====================================================================================================
save it as mysql-restart.sh

sudo nginx-restart.sh
=========================================================================================

#!/bin/sh
sudo service nginx status > /dev/null

if [ $? != 0 ]
then
 echo "nginx stopped"
 sudo service nginx start > /dev/null
 echo "nginx start"
fi

=============================================================
type crontab -e and type the following shell script to run every minute from root cron user.

* * * * * sh -x /usr/local/vesta/bin/mysql-restart.sh
* * * * * sh -x /usr/local/vesta/bin/apache-restart.sh
* * * * * sh -x /usr/local/vesta/bin/nginx-restart.sh

and save it . that's all. in case any problem you can contact me at smrutiniit@gmail.com

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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