Skip to content

Instantly share code, notes, and snippets.

@nicdoye

nicdoye/tomcat7

Created Jan 9, 2013
Embed
What would you like to do?
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
You can’t perform that action at this time.