From d2594ae0a30565e12b0b366a2c00936d60a91531 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Wed, 11 Jun 2014 14:56:36 -0600 Subject: [PATCH 01/16] Initial changes to support Tomcat7 on RedHat 6. Added new version possibility in the params.pp, added default templates, and made setenv.sh.erb use a lookup value instead of having it hard coded. --- manifests/params.pp | 1 + templates/instance/defaults7-RedHat.erb | 63 +++++ templates/instance/init7-RedHat.erb | 290 ++++++++++++++++++++++++ templates/instance/setenv.sh.erb | 2 +- 4 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 templates/instance/defaults7-RedHat.erb create mode 100644 templates/instance/init7-RedHat.erb diff --git a/manifests/params.pp b/manifests/params.pp index 5b98e30..fcb5b03 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -29,6 +29,7 @@ /(?i:CentOS|RedHat|Scientific)/ => $::lsbmajdistrelease ? { 5 => '5', 6 => '6', + 7 => '7', default => '6', }, /(?i:Amazon)/ => $::lsbmajdistrelease ? { diff --git a/templates/instance/defaults7-RedHat.erb b/templates/instance/defaults7-RedHat.erb new file mode 100644 index 0000000..9e8abe8 --- /dev/null +++ b/templates/instance/defaults7-RedHat.erb @@ -0,0 +1,63 @@ +# File Managed by Puppet + +# Service-specific configuration file for tomcat7. This will be sourced by +# the SysV init script after the global configuration file +# /etc/tomcat7/tomcat7.conf, thus allowing values to be overridden in +# a per-service manner. +# +# NEVER change the init script itself. To change values for all services make +# your changes in /etc/tomcat7/tomcat7.conf +# +# To change values for a specific service make your edits here. +# To create a new service create a link from /etc/init.d/ to +# /etc/init.d/tomcat7 (do not copy the init script) and make a copy of the +# /etc/sysconfig/tomcat7 file to /etc/sysconfig/ and change +# the property values so the two services won't conflict. Register the new +# service in the system as usual (see chkconfig and similars). +# + +# Where your java installation lives +<% if @java_home != '' -%> +JAVA_HOME=<%= @java_home %> +<% end -%> + +# Where your tomcat installation lives +CATALINA_BASE="/var/lib/tomcat7-<%= @instance_name %>" +CATALINA_HOME="<%= scope.lookupvar('basedir') %>" +#JASPER_HOME="/usr/share/tomcat7" +#CATALINA_TMPDIR="/var/cache/tomcat7/temp" + +# You can pass some parameters to java here if you wish to +<% if @java_opts != '' -%> +JAVA_OPTS="<%= @java_opts %>" +<% end -%> +<% if @catalina_opts != '' -%> +CATALINA_OPTS="<%= @catalina_opts %>" +<% end -%> + + +# What user should run tomcat +TOMCAT_USER="<%= @instance_owner %>" + +# You can change your tomcat locale here +#LANG="en_US" + +# Run tomcat under the Java Security Manager +#SECURITY_MANAGER="false" + +# Time to wait in seconds, before killing process +#SHUTDOWN_WAIT="30" + +# Whether to annoy the user with "attempting to shut down" messages or not +#SHUTDOWN_VERBOSE="false" + +# Set the TOMCAT_PID location +CATALINA_PID="/var/run/tomcat7-<%= @instance_name %>.pid" + +# Connector port is 8080 for this tomcat7 instance +CONNECTOR_PORT="<%= @control_port %>" + +# If you wish to further customize your tomcat environment, +# put your own definitions here +# (i.e. LD_LIBRARY_PATH for some jdbc drivers) + diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb new file mode 100644 index 0000000..6cdffdf --- /dev/null +++ b/templates/instance/init7-RedHat.erb @@ -0,0 +1,290 @@ +#!/bin/bash +# +# tomcat7 This shell script takes care of starting and stopping Tomcat +# +# chkconfig: - 80 20 +# +### BEGIN INIT INFO +# Provides: tomcat7 +# Required-Start: $network $syslog +# Required-Stop: $network $syslog +# Default-Start: +# Default-Stop: +# Description: Release implementation for Servlet 2.5 and JSP 2.1 +# Short-Description: start and stop tomcat +### END INIT INFO +# +# - originally written by Henri Gomez, Keith Irwin, and Nicolas Mailhot +# - heavily rewritten by Deepak Bhole and Jason Corley +# + +## Source function library. +#. /etc/rc.d/init.d/functions +# Source LSB function library. +if [ -r /lib/lsb/init-functions ]; then + . /lib/lsb/init-functions +else + exit 1 +fi + +DISTRIB_ID=`lsb_release -i -s 2>/dev/null` + +NAME="$(basename $0)" +unset ISBOOT +if [ "${NAME:0:1}" = "S" -o "${NAME:0:1}" = "K" ]; then + NAME="${NAME:3}" + ISBOOT="1" +fi + +# For SELinux we need to use 'runuser' not 'su' +if [ -x "/sbin/runuser" ]; then + SU="/sbin/runuser -s /bin/sh" +else + SU="/bin/su -s /bin/sh" +fi + +# Get the tomcat config (use this for environment specific settings) +TOMCAT_CFG="/etc/tomcat7/tomcat7.conf" +if [ -r "$TOMCAT_CFG" ]; then + . $TOMCAT_CFG +fi + +# Get instance specific config file +if [ -r "/etc/sysconfig/${NAME}" ]; then + . /etc/sysconfig/${NAME} +fi + +# Define which connector port to use +CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" + +# Path to the tomcat launch script +TOMCAT_SCRIPT="/usr/sbin/tomcat7" + +# Tomcat program name +TOMCAT_PROG="${NAME}" + +# Define the tomcat username +TOMCAT_USER="${TOMCAT_USER:-tomcat}" + +# Define the tomcat log file +TOMCAT_LOG="${TOMCAT_LOG:-/var/log/tomcat7/${NAME}-initd.log}" + +# Define the pid file name +# If change is needed, use sysconfig instead of here +export CATALINA_PID="${CATALINA_PID:-/var/run/${NAME}.pid}" + +RETVAL="0" + +function parseOptions() { + options="" + options="$options $( + awk '!/^#/ && !/^$/ { ORS=" "; print "export ", $0, ";" }' \ + $TOMCAT_CFG + )" + if [ -r "/etc/sysconfig/${NAME}" ]; then + options="$options $( + awk '!/^#/ && !/^$/ { ORS=" "; + print "export ", $0, ";" }' \ + /etc/sysconfig/${NAME} + )" + fi + TOMCAT_SCRIPT="$options ${TOMCAT_SCRIPT}" +} + +# rhbz 757632 +function version() { + parseOptions + $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} version" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" +} + +# See how we were called. +function start() { + + echo -n "Starting ${TOMCAT_PROG}: " + if [ "$RETVAL" != "0" ]; then + log_failure_msg + return + fi + if [ -f "/var/lock/subsys/${NAME}" ]; then + if [ -f "${CATALINA_PID}" ]; then + read kpid < ${CATALINA_PID} +# if checkpid $kpid 2>&1; then + if [ -d "/proc/${kpid}" ]; then + log_success_msg + if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then + echo + fi + RETVAL="0" + return + fi + fi + fi + # fix permissions on the log and pid files + touch $CATALINA_PID 2>&1 || RETVAL="4" + if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then + chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID + fi + [ "$RETVAL" -eq "0" ] && touch $TOMCAT_LOG 2>&1 || RETVAL="4" + if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then + chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG + fi + parseOptions + if [ "$RETVAL" -eq "0" -a "$SECURITY_MANAGER" = "true" ]; then + $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" \ + >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + else + + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + fi + if [ "$RETVAL" -eq "0" ]; then + log_success_msg + touch /var/lock/subsys/${NAME} + else + log_failure_msg "Error code ${RETVAL}" + fi + if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then + echo + fi +} + +function stop() { + echo -n "Stopping ${TOMCAT_PROG}: " + if [ -f "/var/lock/subsys/${NAME}" ]; then + parseOptions + if [ "$RETVAL" -eq "0" ]; then + touch /var/lock/subsys/${NAME} 2>&1 || RETVAL="4" + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + fi + if [ "$RETVAL" -eq "0" ]; then + count="0" + if [ -f "${CATALINA_PID}" ]; then + read kpid < ${CATALINA_PID} + until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \ + [ "$count" -gt "$SHUTDOWN_WAIT" ]; do + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + echo "waiting for processes $kpid to exit" + fi + sleep 1 + let count="${count}+1" + done + if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + log_warning_msg "killing processes which did not stop after ${SHUTDOWN_WAIT} seconds" + fi + kill -9 $kpid + fi + log_success_msg + fi + rm -f /var/lock/subsys/${NAME} ${CATALINA_PID} + else + log_failure_msg + RETVAL="4" + fi + else + log_success_msg + RETVAL="0" + fi + if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then + echo + fi +} + +function status() +{ + checkpidfile + if [ "$RETVAL" -eq "0" ]; then + log_success_msg "${NAME} (pid ${kpid}) is running..." + elif [ "$RETVAL" -eq "1" ]; then + log_failure_msg "PID file exists, but process is not running" + else + checklockfile + if [ "$RETVAL" -eq "2" ]; then + log_failure_msg "${NAME} lockfile exists but process is not running" + else + pid="$(/usr/bin/pgrep -u ${TOMCAT_USER} -f ${NAME})" + if [ -z "$pid" ]; then + log_success_msg "${NAME} is stopped" + RETVAL="3" + else + log_success_msg "${NAME} (pid $pid) is running..." + RETVAL="0" + fi + fi + fi +} + +function checklockfile() +{ + if [ -f /var/lock/subsys/${NAME} ]; then + pid="$(/usr/bin/pgrep -u ${TOMCAT_USER} -f ${NAME})" +# The lockfile exists but the process is not running + if [ -z "$pid" ]; then + RETVAL="2" + fi + fi +} + +function checkpidfile() +{ + if [ -f "${CATALINA_PID}" ]; then + read kpid < ${CATALINA_PID} + if [ -d "/proc/${kpid}" ]; then +# The pid file exists and the process is running + RETVAL="0" + else +# The pid file exists but the process is not running + RETVAL="1" + return + fi + fi +# pid file does not exist and program is not running + RETVAL="3" +} + +function usage() +{ + echo "Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}" + RETVAL="2" +} + +# See how we were called. +RETVAL="0" +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + condrestart|try-restart) + if [ -f "/var/run/${NAME}.pid" ]; then + stop + start + fi + ;; + reload) + RETVAL="3" + ;; + force-reload) + if [ -f "/var/run/${NAME}.pid" ]; then + stop + start + fi + ;; + status) + status + ;; + version) + version +# ${TOMCAT_SCRIPT} version + ;; + *) + usage + ;; +esac + +exit $RETVAL diff --git a/templates/instance/setenv.sh.erb b/templates/instance/setenv.sh.erb index 3ad453c..d943898 100644 --- a/templates/instance/setenv.sh.erb +++ b/templates/instance/setenv.sh.erb @@ -2,7 +2,7 @@ # # File managed by puppet: do not modify! -CATALINA_HOME=/usr/share/tomcat6 +CATALINA_HOME=<%= scope.lookupvar('basedir') %> # Let's use Tomcat Native Library LD_LIBRARY_PATH=/usr/local/tomcat-native/lib:$LD_LIBRARY_PATH From f33b7ce35c23c57e2c41a0a17309232243a885ca Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Thu, 12 Jun 2014 17:15:33 -0600 Subject: [PATCH 02/16] Made modifications to allow CATALINA_HOME to be dynamically changed. Kept all default behaviors the same, but extended the functionality. --- manifests/instance.pp | 14 +++++++- templates/instance/tomcat-instance-create.erb | 32 ++++++++++++------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 2fa5e3d..8a999bb 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -5,6 +5,7 @@ $http_port, $control_port, $ajp_port = '', + $https_port = '', $instance_autorestart = 'true', $dirmode = '0755', @@ -18,6 +19,7 @@ $java_opts = '-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC', $catalina_opts = '', + $catalina_home = '', $java_home = '', $catalina_properties_template = '', @@ -119,13 +121,23 @@ default => "-a ${ajp_port}", } + $real_catalina_home = $catalina_home ? { + '' => '', + default => "-t ${catalina_home}", + } + + $real_https_port = $https_port ? { + '' => '', + default => "-s ${https_port}", + } + $real_runtime_dir = $runtime_dir ? { '' => '', default => "-r ${runtime_dir}/${instance_name}", } $instance_create_instance_cmd_exec = $create_instance_cmd_exec ? { - '' => "/usr/bin/tomcat-instance-create -p ${http_port} -c ${control_port} ${real_ajp_port} -w ${magicword} -o ${instance_owner} -g ${instance_group} ${real_runtime_dir} ${instance_path}", + '' => "/usr/bin/tomcat-instance-create -p ${http_port} -c ${control_port} ${real_https_port} ${real_ajp_port} ${real_catalina_home} -w ${magicword} -o ${instance_owner} -g ${instance_group} ${real_runtime_dir} ${instance_path}", default => $create_instance_cmd_exec, } diff --git a/templates/instance/tomcat-instance-create.erb b/templates/instance/tomcat-instance-create.erb index 5bd9901..022fda8 100644 --- a/templates/instance/tomcat-instance-create.erb +++ b/templates/instance/tomcat-instance-create.erb @@ -7,11 +7,13 @@ PROG=`basename $0` TARGET="" HPORT=8080 +SPORT=8443 CPORT=8005 APORT=8009 CWORD="SHUTDOWN" OWNER=root GROUP=root +CATALINA_HOME="/usr/share/<%= scope.lookupvar('tomcat::params::pkgver') %>" warned=0 warnlowport=0 @@ -21,12 +23,14 @@ usage() { echo "Options:" echo " -h, --help Display this help message" echo " -p httpport HTTP port to be used by Tomcat (default is $HPORT)" + echo " -s secureport HTTPS port to be used during redirects by Tomcat (default is $SPORT)" echo " -a ajpport AJP port to be used by Tomcat (default is $APORT)" echo " -c controlport Server shutdown control port (default is $CPORT)" echo " -w magicword Word to send to trigger shutdown (default is $CWORD)" echo " -o owner User that owns the created runtime dirs (default is $OWNER)" echo " -g group Group that owns the created runtime dirs (default is $GROUP)" echo " -r runtimedir Optional Path of a directory where to move webapps, work and tmp dirs" + echo " -t tomcathome Optional Path of the directory CATALINA_HOME, the base of the tomcat installation. (default is ${CATALINA_HOME}" } checkport() { @@ -70,16 +74,17 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then exit 0 fi - -while getopts ":p:c:a:w:o:g:r:h" options; do +while getopts "p:s:c:a:w:o:g:r:t:h" options; do case $options in p ) HPORT=$OPTARG ;; + s ) SPORT=$OPTARG ;; a ) APORT=$OPTARG ;; c ) CPORT=$OPTARG ;; w ) CWORD=$OPTARG ;; o ) OWNER=$OPTARG ;; g ) GROUP=$OPTARG ;; r ) RUNTIMEDIR=$OPTARG ;; + t ) CATALINA_HOME=$OPTARG ;; h ) usage;; * ) echo "Error: Unknown parameter '$OPTARG'." exit 1;; @@ -89,7 +94,6 @@ done shift $(($OPTIND - 1)) TARGET=$1 shift -echo "You are about to create a Tomcat instance in directory '$TARGET'" # Fail if no target specified if [ -z "${TARGET}" ]; then @@ -97,23 +101,27 @@ if [ -z "${TARGET}" ]; then exit 1 fi -# Fail if ports are the same -if [ "${HPORT}" = "${CPORT}" ]; then - echo "Error: HTTP port and control port must be different." - exit 1 -fi - # Fail if target directory already exists if [ -d "${TARGET}" ]; then echo "Error: Target directory already exists." exit 1 fi +echo "You are about to create a Tomcat instance in directory '$TARGET'" + # Check ports +# Fail if ports are the same +if [ "${HPORT}" = "${CPORT}" ]; then + echo "Error: HTTP port and control port must be different." + exit 1 +fi + checkport HTTP "${HPORT}" checkport Control "${CPORT}" [ -z "${APORT}" ] || checkport AJP "${APORT}" +[ -z "${SPORT}" ] || checkport HTTPS "${SPORT}" + # Ask for confirmation if warnings were printed out if [ ${warned} -eq 1 ]; then echo "Type to continue, to abort." @@ -166,17 +174,19 @@ sed -i -e "s/Connector port=\"8080\"/Connector port=\"${HPORT}\"/;s/Server port= sed -i -e "s/Connector port=\"8009\"/Connector port=\"${APORT}\"/g" ${TARGET}/conf/server.xml +sed -i -e "s/redirectPort=\"8443\"/redirectPort=\"${SPORT}\"/g" ${TARGET}/conf/server.xml + cat > ${TARGET}/bin/startup.sh << EOT #!/bin/sh export CATALINA_BASE=${FULLTARGET} -/usr/share/<%= scope.lookupvar('tomcat::params::pkgver') %>/bin/startup.sh +${CATALINA_HOME}/bin/startup.sh echo "Tomcat started" EOT cat > ${TARGET}/bin/shutdown.sh << EOT #!/bin/sh export CATALINA_BASE=${FULLTARGET} -/usr/share/<%= scope.lookupvar('tomcat::params::pkgver') %>/bin/shutdown.sh +${CATALINA_HOME}/bin/shutdown.sh echo "Tomcat stopped" EOT From 0a61a7743c8076e2141c0125cc1fcca48f37d737 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Fri, 13 Jun 2014 13:25:26 -0600 Subject: [PATCH 03/16] Added environment options from tomcat::instance instead of recalculating stuff . --- templates/instance/setenv.sh.erb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/templates/instance/setenv.sh.erb b/templates/instance/setenv.sh.erb index d943898..3030471 100644 --- a/templates/instance/setenv.sh.erb +++ b/templates/instance/setenv.sh.erb @@ -2,7 +2,7 @@ # # File managed by puppet: do not modify! -CATALINA_HOME=<%= scope.lookupvar('basedir') %> +CATALINA_HOME=<%= scope.lookupvar('tomcat::instance::catalina_home') %> # Let's use Tomcat Native Library LD_LIBRARY_PATH=/usr/local/tomcat-native/lib:$LD_LIBRARY_PATH @@ -10,21 +10,27 @@ export LD_LIBRARY_PATH # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) -JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" +JAVA_HOME=<%= scope.lookupvar('tomcat::instance::java_home') %> -# Look for the right JVM to use -for jdir in $JDK_DIRS; do - if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then - JAVA_HOME_TMP="$jdir" +if [ -z "$JAVA_HOME" ]; then + JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" + + # Look for the right JVM to use + for jdir in $JDK_DIRS; do + if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then + JAVA_HOME_TMP="$jdir" # checks for a real JDK like environment, needed to check if # really the java-gcj-compat-dev package is installed if [ -r "$jdir/bin/jdb" ]; then JAVA_HOME="$JAVA_HOME_TMP" fi - fi -done + fi + done +fi # Default Java options +JAVA_OPTS=<%= scope.lookupvar('tomcat::instance::java_opts') %> + if [ -z "$JAVA_OPTS" ]; then JAVA_OPTS="-Djava.awt.headless=true -Xmx128M -XX:+UseCompressedOops" fi From 2f32b693fe5f273dca7af2dcc0da2eba0517ac46 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Fri, 13 Jun 2014 14:26:17 -0600 Subject: [PATCH 04/16] Added refinements to pull parameters from instance variables. --- templates/instance/defaults7-RedHat.erb | 2 +- templates/instance/init7-RedHat.erb | 2 +- templates/instance/setenv.sh.erb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/instance/defaults7-RedHat.erb b/templates/instance/defaults7-RedHat.erb index 9e8abe8..98b3558 100644 --- a/templates/instance/defaults7-RedHat.erb +++ b/templates/instance/defaults7-RedHat.erb @@ -23,7 +23,7 @@ JAVA_HOME=<%= @java_home %> # Where your tomcat installation lives CATALINA_BASE="/var/lib/tomcat7-<%= @instance_name %>" -CATALINA_HOME="<%= scope.lookupvar('basedir') %>" +CATALINA_HOME="<%= @catalina_home %>" #JASPER_HOME="/usr/share/tomcat7" #CATALINA_TMPDIR="/var/cache/tomcat7/temp" diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index 6cdffdf..df637c7 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -58,7 +58,7 @@ fi CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" # Path to the tomcat launch script -TOMCAT_SCRIPT="/usr/sbin/tomcat7" +TOMCAT_SCRIPT=<%= @catalina_home %> # Tomcat program name TOMCAT_PROG="${NAME}" diff --git a/templates/instance/setenv.sh.erb b/templates/instance/setenv.sh.erb index 3030471..f5648c7 100644 --- a/templates/instance/setenv.sh.erb +++ b/templates/instance/setenv.sh.erb @@ -2,7 +2,7 @@ # # File managed by puppet: do not modify! -CATALINA_HOME=<%= scope.lookupvar('tomcat::instance::catalina_home') %> +CATALINA_HOME="<%= @catalina_home %>" # Let's use Tomcat Native Library LD_LIBRARY_PATH=/usr/local/tomcat-native/lib:$LD_LIBRARY_PATH @@ -10,7 +10,7 @@ export LD_LIBRARY_PATH # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) -JAVA_HOME=<%= scope.lookupvar('tomcat::instance::java_home') %> +JAVA_HOME="<%= @java_home %>" if [ -z "$JAVA_HOME" ]; then JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" @@ -29,7 +29,7 @@ if [ -z "$JAVA_HOME" ]; then fi # Default Java options -JAVA_OPTS=<%= scope.lookupvar('tomcat::instance::java_opts') %> +JAVA_OPTS="<%= @java_opts %>" if [ -z "$JAVA_OPTS" ]; then JAVA_OPTS="-Djava.awt.headless=true -Xmx128M -XX:+UseCompressedOops" From 89b44dbe79e72aa8834bc043808f42ce1a5bb8d4 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Fri, 13 Jun 2014 15:00:27 -0600 Subject: [PATCH 05/16] Fixed CRLF --- templates/instance/init7-RedHat.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index df637c7..ce5fcfd 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -58,7 +58,7 @@ fi CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" # Path to the tomcat launch script -TOMCAT_SCRIPT=<%= @catalina_home %> +TOMCAT_SCRIPT=<%= @catalina_home %>/bin/catalina.sh # Tomcat program name TOMCAT_PROG="${NAME}" From 4298f1f0f4d12a1bd883cb49e3bbb7c57271f22e Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Fri, 13 Jun 2014 16:13:45 -0600 Subject: [PATCH 06/16] Change the startup script to now call files in CATALINA_BASE. --- templates/instance/init7-RedHat.erb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index ce5fcfd..bafbfba 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -55,16 +55,18 @@ if [ -r "/etc/sysconfig/${NAME}" ]; then fi # Define which connector port to use -CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" +# CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" # Path to the tomcat launch script -TOMCAT_SCRIPT=<%= @catalina_home %>/bin/catalina.sh +#TOMCAT_SCRIPT=<%= @catalina_home %>/bin/catalina.sh +CATALINA_BASE=<%= @catalina_base %> # Tomcat program name TOMCAT_PROG="${NAME}" # Define the tomcat username -TOMCAT_USER="${TOMCAT_USER:-tomcat}" +#TOMCAT_USER="${TOMCAT_USER:-tomcat}" +TOMCAT_USER=<%= @process_user %> # Define the tomcat log file TOMCAT_LOG="${TOMCAT_LOG:-/var/log/tomcat7/${NAME}-initd.log}" @@ -134,7 +136,7 @@ function start() { >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" else - [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${CATALINA_BASE}/bin/startup.sh" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" fi if [ "$RETVAL" -eq "0" ]; then log_success_msg @@ -153,7 +155,7 @@ function stop() { parseOptions if [ "$RETVAL" -eq "0" ]; then touch /var/lock/subsys/${NAME} 2>&1 || RETVAL="4" - [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + [ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${CATALINA_BASE}/bin/shutdown.sh" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" fi if [ "$RETVAL" -eq "0" ]; then count="0" From add14a3723157990ef6b396d8c93b13ef07667d4 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Mon, 16 Jun 2014 11:10:03 -0600 Subject: [PATCH 07/16] Added params_lookup for package --- manifests/instance.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 8a999bb..410de20 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -10,17 +10,17 @@ $dirmode = '0755', $filemode = '0644', - $owner = '', - $group = '', + $owner = params_lookup( 'owner' ), + $group = params_lookup( 'group' ), $magicword = 'SHUTDOWN', $runtime_dir = '', - $java_opts = '-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC', + $java_opts = params_lookup( 'java_opts' ), $catalina_opts = '', - $catalina_home = '', - $java_home = '', + $catalina_home = params_lookup( 'catalina_home' ), + $java_home = params_lookup( 'java_home' ), $catalina_properties_template = '', $logging_properties_template = '', @@ -38,7 +38,7 @@ $web_xml_template = '', $manager_xml_template = 'tomcat/instance/manager.xml.erb', - $tomcatuser = '', + $tomcatuser = params_lookup ( 'tomcatuser' ), $tomcatpassword = '', $puppi = false, From 976eed30e9dd97e2b63b01516d5ec97deb459725 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Mon, 16 Jun 2014 11:20:17 -0600 Subject: [PATCH 08/16] Revert "Added params_lookup for package" This reverts commit add14a3723157990ef6b396d8c93b13ef07667d4. --- manifests/instance.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 410de20..8a999bb 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -10,17 +10,17 @@ $dirmode = '0755', $filemode = '0644', - $owner = params_lookup( 'owner' ), - $group = params_lookup( 'group' ), + $owner = '', + $group = '', $magicword = 'SHUTDOWN', $runtime_dir = '', - $java_opts = params_lookup( 'java_opts' ), + $java_opts = '-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC', $catalina_opts = '', - $catalina_home = params_lookup( 'catalina_home' ), - $java_home = params_lookup( 'java_home' ), + $catalina_home = '', + $java_home = '', $catalina_properties_template = '', $logging_properties_template = '', @@ -38,7 +38,7 @@ $web_xml_template = '', $manager_xml_template = 'tomcat/instance/manager.xml.erb', - $tomcatuser = params_lookup ( 'tomcatuser' ), + $tomcatuser = '', $tomcatpassword = '', $puppi = false, From 00432e76a4267d5518c4a4035601d185cc39c0e5 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Mon, 16 Jun 2014 14:26:26 -0600 Subject: [PATCH 09/16] Cleaned up some Windows style CRLF, and fixed a variable map. --- templates/instance/init7-RedHat.erb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index bafbfba..99aa554 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -54,20 +54,9 @@ if [ -r "/etc/sysconfig/${NAME}" ]; then . /etc/sysconfig/${NAME} fi -# Define which connector port to use -# CONNECTOR_PORT="${CONNECTOR_PORT:-8080}" - -# Path to the tomcat launch script -#TOMCAT_SCRIPT=<%= @catalina_home %>/bin/catalina.sh -CATALINA_BASE=<%= @catalina_base %> - # Tomcat program name TOMCAT_PROG="${NAME}" -# Define the tomcat username -#TOMCAT_USER="${TOMCAT_USER:-tomcat}" -TOMCAT_USER=<%= @process_user %> - # Define the tomcat log file TOMCAT_LOG="${TOMCAT_LOG:-/var/log/tomcat7/${NAME}-initd.log}" @@ -96,7 +85,9 @@ function parseOptions() { # rhbz 757632 function version() { parseOptions - $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} version" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + $SU - $TOMCAT_USER -c "${CATALINA_HOME}/bin/catalina.sh version" || RETVAL="4" + + } # See how we were called. @@ -198,6 +189,9 @@ function status() log_success_msg "${NAME} (pid ${kpid}) is running..." elif [ "$RETVAL" -eq "1" ]; then log_failure_msg "PID file exists, but process is not running" + elif [ "$RETVAL" -eq "3" ]; then + log_success_msg "${NAME} is stopped" + RETVAL="0" else checklockfile if [ "$RETVAL" -eq "2" ]; then From b735378e02183cb8d4ca72d406e4bc62571c294b Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Mon, 16 Jun 2014 15:30:59 -0600 Subject: [PATCH 10/16] Added explict TOMCAT_LOGS environment variable --- templates/instance/defaults7-RedHat.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/instance/defaults7-RedHat.erb b/templates/instance/defaults7-RedHat.erb index 98b3558..9925f78 100644 --- a/templates/instance/defaults7-RedHat.erb +++ b/templates/instance/defaults7-RedHat.erb @@ -57,6 +57,8 @@ CATALINA_PID="/var/run/tomcat7-<%= @instance_name %>.pid" # Connector port is 8080 for this tomcat7 instance CONNECTOR_PORT="<%= @control_port %>" +TOMCAT_LOG=${CATALINA_BASE}/logs/catalina.out + # If you wish to further customize your tomcat environment, # put your own definitions here # (i.e. LD_LIBRARY_PATH for some jdbc drivers) From c6b07c59e5e0f1e4da84503ce66d86e5084c504d Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Mon, 16 Jun 2014 15:42:00 -0600 Subject: [PATCH 11/16] Changed TOMCAT_LOG --- templates/instance/defaults7-RedHat.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/instance/defaults7-RedHat.erb b/templates/instance/defaults7-RedHat.erb index 9925f78..777e2fe 100644 --- a/templates/instance/defaults7-RedHat.erb +++ b/templates/instance/defaults7-RedHat.erb @@ -57,7 +57,7 @@ CATALINA_PID="/var/run/tomcat7-<%= @instance_name %>.pid" # Connector port is 8080 for this tomcat7 instance CONNECTOR_PORT="<%= @control_port %>" -TOMCAT_LOG=${CATALINA_BASE}/logs/catalina.out +TOMCAT_LOG="$CATALINA_BASE/logs/catalina.out" # If you wish to further customize your tomcat environment, # put your own definitions here From 1df311cb0cc47fcc275db5ac9d44c232ea7f1b33 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Tue, 17 Jun 2014 10:04:18 -0600 Subject: [PATCH 12/16] Fixed a bug with checkpid file where a correctly created pid file was getting a return code of "3". --- templates/instance/init7-RedHat.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index 99aa554..3f4644d 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -213,7 +213,7 @@ function checklockfile() { if [ -f /var/lock/subsys/${NAME} ]; then pid="$(/usr/bin/pgrep -u ${TOMCAT_USER} -f ${NAME})" -# The lockfile exists but the process is not running + # The lockfile exists but the process is not running if [ -z "$pid" ]; then RETVAL="2" fi @@ -225,16 +225,16 @@ function checkpidfile() if [ -f "${CATALINA_PID}" ]; then read kpid < ${CATALINA_PID} if [ -d "/proc/${kpid}" ]; then -# The pid file exists and the process is running + # The pid file exists and the process is running RETVAL="0" else -# The pid file exists but the process is not running + # The pid file exists but the process is not running RETVAL="1" - return fi + else + # pid file does not exist and program is not running + RETVAL="3" fi -# pid file does not exist and program is not running - RETVAL="3" } function usage() From 1dca72bbb8995b0ca716c3db2fc76bdc88077277 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Tue, 17 Jun 2014 12:34:10 -0600 Subject: [PATCH 13/16] Fix stop function to call checkpidfile instead of custom checking, and to call log_success_msg when the process doesn't exist --- templates/instance/init7-RedHat.erb | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index 3f4644d..650f115 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -150,29 +150,31 @@ function stop() { fi if [ "$RETVAL" -eq "0" ]; then count="0" - if [ -f "${CATALINA_PID}" ]; then - read kpid < ${CATALINA_PID} + checkpidfile + if [ "$RETVAL" -eq "0" ] || [ ! -z "$kpdi" ]; then until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \ [ "$count" -gt "$SHUTDOWN_WAIT" ]; do - if [ "$SHUTDOWN_VERBOSE" = "true" ]; then - echo "waiting for processes $kpid to exit" - fi - sleep 1 - let count="${count}+1" - done - if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then - if [ "$SHUTDOWN_VERBOSE" = "true" ]; then - log_warning_msg "killing processes which did not stop after ${SHUTDOWN_WAIT} seconds" - fi - kill -9 $kpid + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + echo "waiting for processes $kpid to exit" fi - log_success_msg + sleep 1 + let count="${count}+1" + done + if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then + if [ "$SHUTDOWN_VERBOSE" = "true" ]; then + log_warning_msg "killing processes which did not stop after ${SHUTDOWN_WAIT} seconds" + fi + kill -9 $kpid fi - rm -f /var/lock/subsys/${NAME} ${CATALINA_PID} - else - log_failure_msg - RETVAL="4" + log_success_msg fi + rm -f /var/lock/subsys/${NAME} ${CATALINA_PID} + log_success_msg + RETVAL="0" + else + log_failure_msg + RETVAL="4" + fi else log_success_msg RETVAL="0" From 027810b7446da47b536d8a2cc6763d26cccf1193 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Tue, 17 Jun 2014 12:48:18 -0600 Subject: [PATCH 14/16] Fixed variable name typo and fixed AND logic after checkpidfile in stop function. This will allow the stop function to successfully complete when the CATALINA_PID file is empty, which is it's default behavior. --- templates/instance/init7-RedHat.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index 650f115..9aa6487 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -151,7 +151,7 @@ function stop() { if [ "$RETVAL" -eq "0" ]; then count="0" checkpidfile - if [ "$RETVAL" -eq "0" ] || [ ! -z "$kpdi" ]; then + if [ "$RETVAL" -eq "0" -a ! -z "${kpid}" ]; then until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \ [ "$count" -gt "$SHUTDOWN_WAIT" ]; do if [ "$SHUTDOWN_VERBOSE" = "true" ]; then From 173e4ec95190c2ecd902f0db9c957d2708e91775 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Tue, 17 Jun 2014 15:35:05 -0600 Subject: [PATCH 15/16] Added PID file content creation to startup.sh script. --- templates/instance/tomcat-instance-create.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/instance/tomcat-instance-create.erb b/templates/instance/tomcat-instance-create.erb index 022fda8..214726a 100644 --- a/templates/instance/tomcat-instance-create.erb +++ b/templates/instance/tomcat-instance-create.erb @@ -179,7 +179,8 @@ sed -i -e "s/redirectPort=\"8443\"/redirectPort=\"${SPORT}\"/g" ${TARGET}/conf/s cat > ${TARGET}/bin/startup.sh << EOT #!/bin/sh export CATALINA_BASE=${FULLTARGET} -${CATALINA_HOME}/bin/startup.sh +export CATALINA_PID=/var/run/${INSTANCE_NAME}.pid +${CATALINA_HOME}/bin/startup.sh & echo $$ >> $CATALINA_PID echo "Tomcat started" EOT From c09532c6078b4176a8373ebac879f9d927ea8f90 Mon Sep 17 00:00:00 2001 From: Jason Looney Date: Wed, 18 Jun 2014 11:10:32 -0600 Subject: [PATCH 16/16] Cleaned up PID handling, and did some additional error handling in the init7-RedHat script to account for empty SHUTDOWN_WAIT times. --- templates/instance/init7-RedHat.erb | 3 +-- templates/instance/tomcat-instance-create.erb | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb index 9aa6487..37040d8 100644 --- a/templates/instance/init7-RedHat.erb +++ b/templates/instance/init7-RedHat.erb @@ -160,13 +160,12 @@ function stop() { sleep 1 let count="${count}+1" done - if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then + if [ ! -z "$SHUTDOWN_WAIT" -a "$count" -gt "$SHUTDOWN_WAIT" ]; then if [ "$SHUTDOWN_VERBOSE" = "true" ]; then log_warning_msg "killing processes which did not stop after ${SHUTDOWN_WAIT} seconds" fi kill -9 $kpid fi - log_success_msg fi rm -f /var/lock/subsys/${NAME} ${CATALINA_PID} log_success_msg diff --git a/templates/instance/tomcat-instance-create.erb b/templates/instance/tomcat-instance-create.erb index 214726a..0390785 100644 --- a/templates/instance/tomcat-instance-create.erb +++ b/templates/instance/tomcat-instance-create.erb @@ -179,16 +179,17 @@ sed -i -e "s/redirectPort=\"8443\"/redirectPort=\"${SPORT}\"/g" ${TARGET}/conf/s cat > ${TARGET}/bin/startup.sh << EOT #!/bin/sh export CATALINA_BASE=${FULLTARGET} -export CATALINA_PID=/var/run/${INSTANCE_NAME}.pid -${CATALINA_HOME}/bin/startup.sh & echo $$ >> $CATALINA_PID -echo "Tomcat started" +export CATALINA_PID=/var/run/tomcat7-${INSTANCE_NAME}.pid +${CATALINA_HOME}/bin/startup.sh +echo "Tomcat started." EOT cat > ${TARGET}/bin/shutdown.sh << EOT #!/bin/sh export CATALINA_BASE=${FULLTARGET} +export CATALINA_PID=/var/run/tomcat7-${INSTANCE_NAME}.pid ${CATALINA_HOME}/bin/shutdown.sh -echo "Tomcat stopped" +echo "Tomcat stopped." EOT chmod a+x ${TARGET}/bin/startup.sh ${TARGET}/bin/shutdown.sh