#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
export TOMCAT_HOME=/usr/share/apache-tomcat-8.0.18/bin
export HOSTNAME=uiharu
export TERM=xterm
export SHELL=/bin/bash
export STOP_TOMCAT=/usr/share/apache-tomcat-8.0.18/bin/shutdown.sh
export USER=dario
export ORACLE_SID=captura
export ORACLE_BASE=/u01/app/oracle
export START_TOMCAT=/usr/share/apache-tomcat-8.0.18/bin/startup.sh
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/metro/bin:/u01/app/oracle/product/10.1.0.3/bin:/sbin:/usr/sbin
export LANG=es_ES.UTF-8
export HOME=/home/dario
export LOGNAME=dario
export ORACLE_HOME=/u01/app/oracle/product/10.1.0.3
export G_BROKEN_FILENAMES=1
export JAVA_HOME=/usr/java/jdk1.8.0_31
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/usr/share/apache-tomcat-8.0.18
export CLASSPATH=/usr/java/jdk1.8.0_31/jre/lib:/usr/java/jdk1.8.0_31/jre/lib/security:/usr/java/jdk1.8.0_31/jre/lib/ext:/usr/java/jdk1.8.0_31/jre/lib:/usr/java/jdk1.8.0_31/db/lib
JAVA_LD_LIBRARY_PATH=/usr/java/jdk1.8.0_31/jre/lib/i386/server:/usr/java/jdk1.8.0_31/jre/lib/i386:/usr/java/jdk1.8.0_31/jre/../lib/i386

cd /usr/share/apache-tomcat-8.0.18/bin
start() {
echo -n "Starting tomcat: "
#if [ ! -e /proc/self ] ; then
#	mount -t proc none /proc
#fi
cd $TOMCAT_HOME
#su metro ${START_TOMCAT}
export LD_LIBRARY_PATH=/usr/java/jdk1.8.0_31/jre/lib/i386:/usr/java/jdk1.8.0_31/jre/lib/i386/jli:/usr/java/jdk1.8.0_31/jre/lib/i386/server
/usr/java/jdk1.8.0_31/jre/bin/java -Djava.util.logging.config.file=/usr/share/apache-tomcat-8.0.18/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/apache-tomcat-8.0.18/endorsed -classpath /usr/share/apache-tomcat-8.0.18/bin/bootstrap.jar:/usr/share/apache-tomcat-8.0.18/bin/tomcat-juli.jar -Dcatalina.base=/usr/share/apache-tomcat-8.0.18 -Dcatalina.home=/usr/share/apache-tomcat-8.0.18 -Djava.io.tmpdir=/usr/share/apache-tomcat-8.0.18/temp org.apache.catalina.startup.Bootstrap start 2>&1 >/dev/null &
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
cd $TOMCAT_HOME
ps -efa | grep org.apache.catalina.startup.Bootstrap | grep -v grep | sed "s/  */ /g;s/^ *//g" | cut -d ' ' -f 2 | xargs kill
#su metro ${STOP_TOMCAT}
while ps -efa | grep -v grep | grep org.apache.catalina.startup.Bootstrap >/dev/null ; do
	echo -n "."
	sleep 1
done
#if [ -e /proc/self ] ; then
#	umount /proc
#fi
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
