Skip to content

Instantly share code, notes, and snippets.

@isa
Last active December 12, 2015 00:48
Show Gist options
  • Save isa/4686267 to your computer and use it in GitHub Desktop.
Save isa/4686267 to your computer and use it in GitHub Desktop.
Tomcat service script for RHEL/CentOS and Ubuntu
#!/bin/env bash
# chkconfig: 2345 80 05
# description: Starts and stops the Tomcat
#
# if you are doing tomcat instancing, you might wanna check the CATALINA_PID logic down here to create something more dynamic behavior
# other than that just add this file under /etc/init.d/ as tomcat and use chkconfig to configure
#
# chkconfig --add tomcat
# chkconfig --level 2345 tomcat on
# chkconfig --list tomcat
#
# and use it like service tomcat start|stop|restart|status
export JAVA_HOME=/usr/java/default
export CATALINA_HOME=/opt/tomcat
export CATALINA_PID=/opt/tomcat/service.pid
export PATH=$JAVA_HOME/bin:$PATH
case "$1" in
start)
$CATALINA_HOME/bin/startup.sh
;;
stop)
$CATALINA_HOME/bin/shutdown.sh
;;
restart)
$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh
;;
status)
if [[ -f $CATALINA_PID ]]; then
PID=`cat $CATALINA_PID`
IS_RUNNING=`ps -e | awk '{ print $1 }' | grep $PID`
if [[ $IS_RUNNING ]]; then
echo "Tomcat is running with process ID: $PID"
else
echo "Tomcat is not running!"
fi
else
echo "Tomcat is not running!"
fi
;;
esac
exit 0
@umit
Copy link

umit commented Apr 23, 2013

:) 8080 killer

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment