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/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..777e2fe --- /dev/null +++ b/templates/instance/defaults7-RedHat.erb @@ -0,0 +1,65 @@ +# 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="<%= @catalina_home %>" +#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 %>" + +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) + diff --git a/templates/instance/init7-RedHat.erb b/templates/instance/init7-RedHat.erb new file mode 100644 index 0000000..37040d8 --- /dev/null +++ b/templates/instance/init7-RedHat.erb @@ -0,0 +1,287 @@ +#!/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 + +# Tomcat program name +TOMCAT_PROG="${NAME}" + +# 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 "${CATALINA_HOME}/bin/catalina.sh version" || 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 "${CATALINA_BASE}/bin/startup.sh" >> ${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 "${CATALINA_BASE}/bin/shutdown.sh" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4" + fi + if [ "$RETVAL" -eq "0" ]; then + count="0" + checkpidfile + 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 + echo "waiting for processes $kpid to exit" + fi + sleep 1 + let count="${count}+1" + done + 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 + 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" + 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" + elif [ "$RETVAL" -eq "3" ]; then + log_success_msg "${NAME} is stopped" + RETVAL="0" + 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" + fi + else + # pid file does not exist and program is not running + RETVAL="3" + fi +} + +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..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=/usr/share/tomcat6 +CATALINA_HOME="<%= @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="<%= @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="<%= @java_opts %>" + if [ -z "$JAVA_OPTS" ]; then JAVA_OPTS="-Djava.awt.headless=true -Xmx128M -XX:+UseCompressedOops" fi diff --git a/templates/instance/tomcat-instance-create.erb b/templates/instance/tomcat-instance-create.erb index 5bd9901..0390785 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,18 +174,22 @@ 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 -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} -/usr/share/<%= scope.lookupvar('tomcat::params::pkgver') %>/bin/shutdown.sh -echo "Tomcat stopped" +export CATALINA_PID=/var/run/tomcat7-${INSTANCE_NAME}.pid +${CATALINA_HOME}/bin/shutdown.sh +echo "Tomcat stopped." EOT chmod a+x ${TARGET}/bin/startup.sh ${TARGET}/bin/shutdown.sh