Current File : //root/panel/restartscript.sh
#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
SERVICE_PATH=`whereis service | awk '{print $2}'`
RESTART="$SERVICE_PATH httpd restart"
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"
#path to pgrep command
PGREP=`whereis pgrep | awk '{print $2}'`
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
# find httpd pid
$PGREP ${HTTPD} -x
if [ $? -ne 0 ] # if apache not running
then
 # restart apache
 $RESTART
fi
# Rsyslog restart script start
RSYSLOG="rsyslog"
LOGRESTART="$SERVICE_PATH rsyslog restart"
$PGREP ${RSYSLOG}
if [ $? -ne 0 ] 
then
 $LOGRESTART
fi
#Rsyslo restart script end
#mysqld restart script start
MYSQL="mysqld"
MYSQLRESTART="$SERVICE_PATH mysqld restart"
$PGREP ${MYSQL}
if [ $? -ne 0 ]
then
 $MYSQLRESTART
fi
#mysqld restart script end
# named  script start
NAMED="named"
NAMEDRESTART="$SERVICE_PATH named restart"
$PGREP ${NAMED}
if [ $? -ne 0 ]
then
$NAMEDRESTART
fi
#named script end
#postfix restart script start
MASTER="master"
MASTERRESTART="$SERVICE_PATH postfix restart"
$PGREP ${MASTER}
if [ $? -ne 0 ]
then
 $MASTERRESTART
fi
#postfix restart script end
#dovecot restart script start
DOVECOT="dovecot"
DOVECOTRESTART="$SERVICE_PATH dovecot restart"
$PGREP ${DOVECOT}
if [ $? -ne 0 ]
then
 $DOVECOTRESTART
fi
#dovecot restart script end
#spamassassin restart script start
SPAMD="spamd"
SPAMDRESTART="$SERVICE_PATH spamassassin restart"
$PGREP ${SPAMD}
if [ $? -ne 0 ]
then
 $SPAMDRESTART
fi
#spamassassin restart script end
#CROND  restart script start
CROND="crond"
CRONDRESTART="$SERVICE_PATH crond restart"
$PGREP ${CROND}
if [ $? -ne 0 ]
then
 $CRONDRESTART
fi
#CROND restart script end
#csf  restart script start
LFD="lfd"
$PGREP ${LFD}
if [ $? -ne 0 ]
then
CSF_PATH=`whereis csf | awk '{print $2}'`
$CSF_PATH -e
$CSF_PATH -r
$SERVICE_PATH csf restart
$SERVICE_PATH lfd restart
fi
#csf  restart script end
# proftpd
#proftpd  restart script start
PROFTPD="proftpd"
PROFTPDRESTART="$SERVICE_PATH proftpd restart"
$PGREP ${PROFTPD}
if [ $? -ne 0 ]
then
 $PROFTPDRESTART
fi
LIGHTTPD="lighttpd"
LIGHTTPDRESTART="$SERVICE_PATH lighttpd restart"
$PGREP ${LIGHTTPD} -x
if [ $? -ne 0 ]
then
 $LIGHTTPDRESTART
fi
OPENDKIM="opendkim"
OPENDKIMRESTART="$SERVICE_PATH opendkim restart"
$PGREP ${OPENDKIM}
if [ $? -ne 0 ]
then
 $OPENDKIMRESTART
fi
#proftpd restart script end
LSOF_LIB=`whereis lsof | awk '{print $2}'`
HTTPD_LISTEN=`$LSOF_LIB -i tcp:8080 | awk '{print$1}' | awk 'END{print}'`
PORTEIGHTY=`$LSOF_LIB -i tcp:80 | awk '{print$1}' | awk 'END{print}'`
if [[ $PORTEIGHTY = "" ]]
then
echo "No one running on the port 80"
        if [[ $HTTPD_LISTEN = "httpd" ]]
        then
        echo "httpd listen 8080" 
                echo "if varnish is not running Need to restart varnish"
                JAVA_CHK=`whereis java | awk '{print $2}'`
                if [[ $JAVA_CHK = "" ]]
                then
                echo "No java"
                        VARNISH="varnish"
                        VARNISHRESTART="$SERVICE_PATH varnish restart"
                        $PGREP ${VARNISH}
                        if [ $? -ne 0 ]
                        then
                         $VARNISHRESTART
                        fi
                else
                echo "$JAVA_CHK java is there"
                fi
        else
        echo "No need to check it"
        fi
else
echo "something running on 80"
fi
$SERVICE_PATH varnish status
PGREP=`whereis pgrep | awk '{print $2}'`
AISA="aisa"
$PGREP ${AISA} -x
if [ $? -ne 0 ] # if apache not running
then
/root/scripts/makeaisa/./aisa >> /root/scripts/aisa/aisa.log &
fi
sshdpid=`cat /var/run/sshd.pid`
lighttpdpid=`cat /var/run/lighttpd.pid`
renice -5 $sshdpid
renice -10 $lighttpdpid