Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created January 9, 2013 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdoye/4494739 to your computer and use it in GitHub Desktop.
Save nicdoye/4494739 to your computer and use it in GitHub Desktop.
Very simple Init Script for Tomcat 7 (works for 6, too). Tested on RHEL 6. Should work on RHEL 5 and SLES, too. Relies on file /etc/sysconfig/tomcat7 which contains two variables RUN_AS_USER (who to run) and CATALINA_HOME. Everything else (JAVA_OPTS, CATALINA_OPTS, CATALINA_PID) is set in $CATALINA_HOME/bin/setenv.sh
#!/bin/bash
#
# Init file for Tomcat 7 server
#
# chkconfig: 2345 80 20
# description: Tomcat 7 server
#
# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/tomcat7
start() {
echo "Starting Tomcat 7: "
if [ "x$USER" != "x$RUN_AS_USER" ]; then
su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
else
$CATALINA_HOME/bin/startup.sh
fi
echo "done."
}
stop() {
echo "Shutting down Tomcat 7: "
if [ "x$USER" != "x$RUN_AS_USER" ]; then
su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
else
$CATALINA_HOME/bin/shutdown.sh
fi
sleep 10
echo "Hard killing any remaining threads.."
pkill -u ${RUN_AS_USER} java
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment