Tomcat Multi-Instance Startup Script (run.sh)


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. # tomcat version
  4. TOMCAT_VERSION="tomcat-7.0.14"
  5. CONF="$1"
  6. ACTION="$2"
  7.  
  8. if [ -z "$1" -o -z "$2" ]; then
  9. echo "usage: run.sh <configuration> [start|stop]"
  10. exit -1
  11. fi
  12.  
  13. if [ `whoami` != "tomcat" ]; then
  14. echo " # ================================================== "
  15. echo " # !!! WARNING !!! "
  16. echo " # You are not running under the user 'tomcat' "
  17. echo " # "
  18. echo " # We're guessing you probably meant to run: "
  19. echo " # sudo su -c \"./run.sh $1 $2\" tomcat "
  20. echo " # "
  21. echo " # This script will assume you meant to run the above "
  22. echo " # command and will continue. You may be prompted for "
  23. echo " # because of 'su' command rights.... "
  24. echo " # ================================================== "
  25. sudo su -c "./run.sh $1 $2" tomcat
  26. exit -1
  27. fi
  28.  
  29. # dynamically assign:
  30. # * shutdown port
  31. # * jmx port
  32. # * jpda port
  33. let SHUTDOWN_PORT=CONF+1
  34. let JMX_PORT=CONF+2
  35. let JPDA_PORT=CONF+3
  36.  
  37. # standard tomcat environmental options
  38. export JRE_HOME=/opt/dev/java
  39. export JAVA_HOME=/opt/dev/java
  40. export JPDA_ADDRESS=$JPDA_PORT
  41. export JPDA_TRANSPORT=dt_socket
  42. export CATALINA_BASE="`pwd`/$CONF"
  43. export CATALINA_HOME="`pwd`/$TOMCAT_VERSION"
  44. export CATALINA_CONF="`pwd`/shared/server.xml"
  45. export LOGGING_CONFIG="-Djava.util.logging.config.file=`pwd`/shared/logging.properties"
  46.  
  47. # jmx support turned on
  48. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"
  49. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.authenticate=true"
  50. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
  51. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.access.file=`pwd`/shared/jmxremote.access"
  52. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.password.file=`pwd`/shared/jmxremote.password"
  53. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT"
  54.  
  55. # pass through shutdown and http port to server.xml
  56. export JAVA_OPTS="$JAVA_OPTS -Dhttp.port=$CONF -Dshutdown.port=$SHUTDOWN_PORT"
  57.  
  58. exec "$CATALINA_HOME/bin/catalina.sh" jpda "$ACTION" -config $CATALINA_CONF
  59.  
  60. Tomcat 7.0.14
  61.  
  62. /S

URL: http://terranceasnyder.com/2011/05/tomcat-best-practices/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.