Hola amigos, en las tareas del dia a dia me encontré con el tema de tener que reiniciar un servidor tomcat de manera automatica, la solicion fue buscar un script de bash que realizara la tarea.
me he encontrado este script muy interesante y con bastantes validaciones les dejo la url:
http://java360.blogspot.com/2012/03/restart-tomcat-via-shell-script-using.html
por si acaso copio el contenido porque puede que despues no se encuentre disponible...
#!/bin/bash
#Important!! Script Must be run as root(you can ignore this if your tomcat does not need root
PATH=$PATH:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/ant/bin:/opt/java/
export PATH
NOW=$(date +"%Y%m-%dT%H%M")
if [ "$(id -u)" != "0" ];
then
echo "This script must be run as root" 1>&2
exit 1
fi
echo `date` ":=================================" >> /tmp/tomcat-restart.log
echo `date` ":Tomcat restart script initiated!!" >> /tmp/tomcat-restart.log
echo `date` ":=================================" >> /tmp/tomcat-restart.log
if [ `ps -ef | egrep 'tomcat6' | egrep -v egrep | wc -l` -gt 0 ];
then
echo `date` ":Tomcat is running" >> /tmp/tomcat-restart.log
kill -3 `ps ax | grep tomcat6 | grep -v grep | awk '{print $1}'`
/opt/tomcat/bin/catalina.sh stop
echo `date` ":Tomcat has shutdown" >> /tmp/tomcat-restart.log
if [ `ps -ef | egrep 'tomcat6' | egrep -v egrep | wc -l` -gt 0 ];
then
kill -9 `ps ax | grep tomcat6 | grep -v grep | awk '{print $1}'`
fi
#echo "Restarting tomcat !!!!!" >> /tmp/tomcat-restart.log
#/opt/tomcat/bin/catalina.sh start
#else
#echo "Tomcat not found running" >> /tmp/tomcat-restart.log
#echo "Restarting tomcat !!!!!" >> /tmp/tomcat-restart.log
#/opt/tomcat/bin/catalina.sh start
fi
echo `date` "Sleep started" >> /tmp/tomcat-restart.log
sleep 30
echo `date` "Sleep End" >> /tmp/tomcat-restart.log
if [ `ps -ef | egrep 'tomcat6' | egrep -v egrep | wc -l` -eq 0 ];
then
/opt/tomcat/bin/catalina.sh start
echo `date` "Tomcat restarted." >> /tmp/tomcat-restart.log
fi
No hay comentarios:
Publicar un comentario
Agradezco el interes en el tema, estaré atento para poder leer su comentario.