Created
January 9, 2013 16:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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