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

type following..



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

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


sudo service nginx status > /dev/null

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

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

* * * * * sh -x /usr/local/vesta/bin/
* * * * * sh -x /usr/local/vesta/bin/
* * * * * sh -x /usr/local/vesta/bin/

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


mysql restart from cron using shell script

check crontab -u root -l - list of cron for user root
cd /home/smruti/
sudo nano
/usr/bin/mysqladmin ping| grep 'mysqld is alive' > /dev/null 2>&1
if [ $? != 0 ]
    sudo service mysqld restart
save as
To make it executable chmod 0755
create cron job  crontab -e from command 
type * * * * * sh -x /home/smruti/
press esc :wq for save

check it by type sudo service mysqld stop
it will automatically start after 1 min.

Install vesta control panel with nginx php5-fpm mysql

Now execute the command below to download Vestacp installation file:
1.curl -O

2. run below command

bash –nginx yes –phpfpm yes –apache no –vsftpd yes –proftpd no –exim no –dovecot no –spamassassin no –clamav no –named yes –iptables yes –fail2ban yes –mysql yes –postgresql no –remi yes –quota no



mysql restart shell script

# mysql root/admin username
# mysql admin/root password
#nano /usr/etc/mysql/debian.cnf
# mysql server hostname
#Shell script to start MySQL server i.e. path to MySQL daemon start/stop script.
# Debain uses following script, need to setup this according to your UNIX/Linux/BSD OS.
MSTART=”/etc/init.d/mysql start”
# Email ID to send notification
# path to mail program
#MAILCMD=”$(which mail)”
# path mysqladmin

#### DO NOT CHANGE anything BELOW ####

$MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]; then
echo “Error: MySQL Server is not running/responding ping request”>>$MAILMESSAGE
echo “Hostname: $(hostname)” >>$MAILMESSAGE
echo “Date & Time: $(date)” >>$MAILMESSAGE
# try to start mysql
$MSTART > /dev/null
# see if it is started or not
o=$(ps cax | grep -c ‘ mysqld$’)
if [ $o -eq 1 ]; then
sMess=”MySQL Server MySQL server successfully restarted”
sMess=”MySQL server FAILED to restart”
# Email status too
echo “Current Status: $sMess” >>$MAILMESSAGE
echo “” >>$MAILMESSAGE
echo “*** This email generated by $(basename $0) shell script ***” >>$MAILMESSAGE
echo “*** Please don’t reply this email, this is just notification email ***” >>$MAILMESSAGE
# send email
else # MySQL is running 🙂 and do nothing
# remove file

Configure mysql

sudo apt-get install mysql-server php5-mysql

sudo /usr/bin/mysql_secure_installation

change root passsword: n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Configure phpmyadmin on Nginx

sudo apt-get update
sudo apt-get install phpmyadmin

During the installation, you will be prompted for some information. It will ask you which web server you would like the software to automatically configure. Since Nginx, the web server we are using, is not one of the available options, you can just hit TAB to bypass this prompt.

The next prompt will ask if you would like dbconfig-common to configure a database for phpmyadmin to use. Select “Yes” to continue.

You will need to enter the database administrative password that you configured during the MySQL installation to allow these changes. Afterward, you will be asked to select and confirm a password for a new database that will hold phpMyAdmin’s own data.

The installation will now complete. For the Nginx web server to find and serve the phpMyAdmin files correctly, we just need to create a symbolic link from the installation files to our Nginx document root directory by typing this:

sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/html

sudo php5enmod mcrypt
sudo service php5-fpm restart

sudo nano /etc/nginx/sites-available/default

sudo service nginx restart