#!/bin/bash
# apache-tomcat
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/usr/local/apache-tomcat-6.0.37"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su -s /bin/bash tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
=========================
Based on tomcat uptime
#!/bin/bash
SERVER=`hostname -s | sed s/hostname//g`
TOMCAT_HOME=/usr/local/apache-tomcat
SHUTDOWN_WAIT=20
LOG_FILE=/mnt/esb/test/support/scripts/log/tomcat_restart.log
TIME_STAMP=`date +'%b %e %R '` "$@"
pid=`ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
pdays=`ps -eo pid,comm,etime | grep $pid | grep -v grep |awk '{print $3}'`
export index=0
index=`expr index "$pdays" '-'`
uptime_days=${pdays:0:$index-1}
echo "$TIME_STAMP Complete Uptime days of the process `ps -p $pid -o comm=` with pid=$pid is $uptime_days days" >> $LOG_FILE
if [ $uptime_days -ge 28 ]; then
if [ -n "$pid" ]; then
echo "$TIME_STAMP- Stoping Tomcat on $SERVER with pid=$pid" >> $LOG_FILE
$TOMCAT_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo "$TIME_STAMP- waiting for processes with pid=$pid to exit" >> $LOG_FILE
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo "$TIME_STAMP- killing processes with pid=$pid which didn't stop after $SHUTDOWN_WAIT seconds" >> $LOG_FILE
kill -9 $pid
fi
else
echo "$TIME_STAMP- Tomcat is not running" >> $LOG_FILE
fi
echo "$TIME_STAMP- Starting Tomcat ..." >> $LOG_FILE
/etc/init.d/tomcat start
fi
# apache-tomcat
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/usr/local/apache-tomcat-6.0.37"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su -s /bin/bash tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
=========================
Based on tomcat uptime
#!/bin/bash
SERVER=`hostname -s | sed s/hostname//g`
TOMCAT_HOME=/usr/local/apache-tomcat
SHUTDOWN_WAIT=20
LOG_FILE=/mnt/esb/test/support/scripts/log/tomcat_restart.log
TIME_STAMP=`date +'%b %e %R '` "$@"
pid=`ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
pdays=`ps -eo pid,comm,etime | grep $pid | grep -v grep |awk '{print $3}'`
export index=0
index=`expr index "$pdays" '-'`
uptime_days=${pdays:0:$index-1}
echo "$TIME_STAMP Complete Uptime days of the process `ps -p $pid -o comm=` with pid=$pid is $uptime_days days" >> $LOG_FILE
if [ $uptime_days -ge 28 ]; then
if [ -n "$pid" ]; then
echo "$TIME_STAMP- Stoping Tomcat on $SERVER with pid=$pid" >> $LOG_FILE
$TOMCAT_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo "$TIME_STAMP- waiting for processes with pid=$pid to exit" >> $LOG_FILE
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo "$TIME_STAMP- killing processes with pid=$pid which didn't stop after $SHUTDOWN_WAIT seconds" >> $LOG_FILE
kill -9 $pid
fi
else
echo "$TIME_STAMP- Tomcat is not running" >> $LOG_FILE
fi
echo "$TIME_STAMP- Starting Tomcat ..." >> $LOG_FILE
/etc/init.d/tomcat start
fi
No comments:
Post a Comment