Tuesday, April 14, 2015

Puppet3.7.5 Tomcat8 installation automation(2)-improved

* If tomcat8 is already installed and running,just do not do anything.
* If tomcat server.xml is changed, restart service.
* Test
1. Change 8080 default tomcat port to 8081
2.  On each test with netstat command.
###################################################


 root@puppet:/etc/puppet/modules/tomcat8/templates# vi server.xml.erb

 <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8081" protocol="HTTP/1.1"

# On centos7 node
 [root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ct7
Info: Applying configuration version '1429017922'
Notice: /Stage[main]/Tomcat8/Exec[yum-update]/returns: executed successfully
Notice: /Stage[main]/Tomcat8::Centos7_config/File[/usr/local/tomcat8/conf/server.xml]/content:
--- /usr/local/tomcat8/conf/server.xml    2015-04-14 13:13:54.794755928 +0000
+++ /tmp/puppet-file20150414-5675-tv54yg    2015-04-14 13:25:22.537792383 +0000
@@ -66,7 +66,7 @@
          APR (HTTP/AJP) Connector: /docs/apr.html
          Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
     -->
-    <Connector port="8080" protocol="HTTP/1.1"
+    <Connector port="8081" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="8443" />
     <!-- A "Connector" using the shared thread pool-->

Info: Computing checksum on file /usr/local/tomcat8/conf/server.xml
Info: /Stage[main]/Tomcat8::Centos7_config/File[/usr/local/tomcat8/conf/server.xml]: Filebucketed /usr/local/tomcat8/conf/server.xml to puppet with sum fb17bc2e40512ffb3502ec5becc5cf40
Notice: /Stage[main]/Tomcat8::Centos7_config/File[/usr/local/tomcat8/conf/server.xml]/content: content changed '{md5}fb17bc2e40512ffb3502ec5becc5cf40' to '{md5}2cde2608fc6616cd30824404c6300eb3'
Info: /Stage[main]/Tomcat8::Centos7_config/File[/usr/local/tomcat8/conf/server.xml]: Scheduling refresh of Service[tomcat8]
Notice: /Stage[main]/Tomcat8/Service[tomcat8]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.71 seconds


[root@ct7 ~]# netstat -tpln | grep 8081
tcp6       0      0 :::8081                 :::*                    LISTEN      5900/java  

# On ubuntu 14.04 node
 root@ts:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts
Info: Applying configuration version '1429017922'
Notice: /Stage[main]/Java::Oracle_jdk7/File[/tmp/oracle-java7-installer.preseed]/ensure: defined content as '{md5}0ab981127e3d597b2175f9959eb70c3f'
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/usr/local/tomcat8/conf/server.xml]/content:
--- /usr/local/tomcat8/conf/server.xml    2015-04-14 13:12:07.167239026 +0900
+++ /tmp/puppet-file20150414-1802-1wa3zg2    2015-04-14 22:27:07.940778039 +0900
@@ -19,7 +19,7 @@
      define subcomponents such as "Valves" at this level.
      Documentation at /docs/config/server.html
  -->
-<Server port="8017" shutdown="SHUTDOWN">
+<Server port="8010" shutdown="SHUTDOWN">
   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
   <!-- Security listener. Documentation at /docs/config/listeners.html
   <Listener className="org.apache.catalina.security.SecurityListener" />
@@ -66,7 +66,7 @@
          APR (HTTP/AJP) Connector: /docs/apr.html
          Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
     -->
-    <Connector port="8080" protocol="HTTP/1.1"
+    <Connector port="8081" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="8443" />
     <!-- A "Connector" using the shared thread pool-->

Info: Computing checksum on file /usr/local/tomcat8/conf/server.xml
Info: /Stage[main]/Tomcat8::Ubuntu_config/File[/usr/local/tomcat8/conf/server.xml]: Filebucketed /usr/local/tomcat8/conf/server.xml to puppet with sum 1999427b3c2cec8edfa14e916b7c9d1d
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/usr/local/tomcat8/conf/server.xml]/content: content changed '{md5}1999427b3c2cec8edfa14e916b7c9d1d' to '{md5}2cde2608fc6616cd30824404c6300eb3'
Info: /Stage[main]/Tomcat8::Ubuntu_config/File[/usr/local/tomcat8/conf/server.xml]: Scheduling refresh of Service[tomcat8]
Notice: /Stage[main]/Tomcat8/Service[tomcat8]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Tomcat8/Service[tomcat8]: Unscheduling refresh on Service[tomcat8]
Notice: Finished catalog run in 5.57 seconds


 root@ts:~# netstat -tpln | grep 8081
tcp6       0      0 :::8081                 :::*                    LISTEN      2108/java    

###################################################








* From not on, just cat and paste..^^;


*init.pp
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat init.pp
class tomcat8 {
     include tomcat8::account_add
     $instance_owner = "tomcat8"
     $instance_group = "tomcat8"
     $service_name = "tomcat8"
     $java_opts = "-Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC"
     #$java_opts = "-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"
     $catalina_home = "/usr/local/tomcat8"
     $catalina_base = "/usr/local/tomcat8"
     $catalina_pid= "/usr/local/tomcat8/tomcat8.pid"
     $java_security_manager = "no"
    
case $::operatingsystem {
   'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
     #java install
     class { 'java': }
     $java_home = "/usr/local/java"
     $instance_name = "centos7-tomcat8"

     #In case of new config as in tomcat8
     include tomcat8::centos7_config
     # do something RHEL specific
     #execute 'yum update'
     exec { 'yum-update':
       command => '/bin/yum -y update'
     }
     # if service tomcat8 is running does not get tomcat8 files and no installation.
     if ! defined(Service['tomcat8']){
     include tomcat8::get_tomcat
     }

     #running service
     #exec { 'tomcat8-start':
     # name => $service_name,
     # path => ['/bin','/usr/bin','/usr/sbin','/sbin'],
     # command => 'systemctl daemon-reload && systemctl start tomcat8 && systemctl enable tomcat8',
     #}
      # running tomcat8
     service { 'tomcat8':
      provider => "systemd",
      name => $service_name,
      ensure => running,
      enable => true,
     }

   }

   'ubuntu': {
     #java install
     class { 'java': }
     #In case of new config as in tomcat8
     include tomcat8::ubuntu_config
     #tomcat version and compressed file
     $java_home = "/usr/lib/jvm/java-7-oracle"
     $default_file = "/etc/default/tomcat8"
     $instance_name = "ubuntu-trusty-tomcat8"

     if ! defined(Service['tomcat8']){
     include tomcat8::get_tomcat
     }

      # running tomcat8
     service { 'tomcat8':
      name => $service_name,
      ensure => running,
      enable => true,
     }
    
   }
   default: {
     # ...
   }
 }
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat account_add.pp
class tomcat8::account_add {
    user { "tomcat8":
        comment => "tomcat8user",
        home => "/usr/local/tomcat8",
        managehome => "false",
        shell => "/bin/false",
        uid => 109,
        gid => 118,
    }

    group { "tomcat8":
        gid => 118,
    }
     
     
}
root@puppet:/etc/puppet/modules/tomcat8/manifests#

root@puppet:/etc/puppet/modules/tomcat8/manifests# cat centos7_config.pp
class tomcat8::centos7_config {
   file { "/etc/systemd/system/tomcat8.service":
     ensure => present,
     owner => 'root',
     group => 'root',
     mode => 0700,
     #enable => true,
     content => template('tomcat8/centos7-tomcat8.erb'),
   }
   #server.xml copy and restart#
   file {"/usr/local/tomcat8/conf/server.xml":
         notify => Service["tomcat8"],
         ensure => present,
         owner => 'tomcat8',
         group => 'tomcat8',
         mode => '0644',
         content => template('tomcat8/server.xml.erb'),
    }

}

class tomcat8::get_tomcat {
     $TOMCAT="apache-tomcat"
     $TOMCAT_DIR="tomcat-8"
     $TOMCAT_VERSION="8.0.21"
     $COMP=".tar.gz"
     $INSTALL_DIR="/usr/local/tomcat8"
     $POLICY_DIR="$INSTALL_DIR/conf/policy.d"
     $instance_owner = "tomcat8"
     $instance_group = "tomcat8"
     $catalina_pid= "/var/run/tomcat8.pid"



     exec { 'wget-tomcat':
      path => ['/bin','/usr/bin'],
      cwd => '/tmp',
      #using mirror
      #command => "wget http://mirrors.advancedhosters.com/apache/tomcat/$TOMCAT_DIR/v$TOMCAT_VERSION/bin/$TOMCAT-$TOMCAT_VERSION$COMP",
      #using local web server
      command => "wget http://10.0.0.100/$TOMCAT-$TOMCAT_VERSION$COMP && tar xvzf $TOMCAT-$TOMCAT_VERSION$COMP",
      # if tomcat8 already exists, do not execute puppet module
      unless => "ls $INSTALL_DIR",
     }


     exec { 'tomcat-install':
      path => ['/bin','/usr/bin'],
      cwd => '/tmp',
      command => "mv $TOMCAT-$TOMCAT_VERSION $INSTALL_DIR && mkdir $POLICY_DIR && chown -R $instance_owner:$instance_group $INSTALL_DIR && chmod 0755 $INSTALL_DIR/conf && chown -R root:root $INSTALL_DIR/conf &&  chown -R root:$instance_group $INSTALL_DIR/conf/* && chmod 644 $INSTALL_DIR/conf/* && chmod 0755 $POLICY_DIR",
      unless => "ls $INSTALL_DIR",
      require => Exec['wget-tomcat'],
     }

 }


root@puppet:/etc/puppet/modules/tomcat8/manifests# cat ubuntu_config.pp
class tomcat8::ubuntu_config {
   file { "/etc/init.d/tomcat8":
     ensure => present,
     owner => 'root',
     group => 'root',
     mode => 0755,
     content => template('tomcat8/ubuntu-tomcat8.erb'),
   }

   file { "/etc/default/tomcat8":
          ensure => present,
          owner => 'root',
          group => 'root',
          mode => 0640,
          content => template('tomcat8/ubuntu-default-tomcat8.erb'),
    }

   file {"/usr/local/tomcat8/conf/server.xml":
         notify => Service["tomcat8"],
         ensure => present,
         owner => 'tomcat8',
         group => 'tomcat8',
         mode => '0644',
         content => template('tomcat8/server.xml.erb'),
    }



    
}



root@puppet:/etc/puppet/modules/tomcat8/templates# cat centos7-tomcat8.erb
[Unit]
Description=Tomcat8
After=network.target

[Service]
Type=forking
User=<%= @instance_owner %>
Group=<%= @instance_group %>

Environment=CATALINA_PID=<%= @catalina_pid %>
Environment=JAVA_HOME=<%= @java_home %>
Environment=TOMCAT_JAVA_HOME=<%= @java_home %>
Environment=CATALINA_HOME=<%= @catalina_home %>
Environment=CATALINA_BASE=<%= @catalina_base %>
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=<%= @java_opts %>"

ExecStart=<%= @catalina_home %>/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target


root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-default-tomcat8.erb
# File Managed by Puppet

# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>

# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>

# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>

# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>

# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac

# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no

# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14

# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp

# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind.  It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4.  Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no




root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-tomcat8.erb
#!/bin/sh
# File Managed by Puppet
#
# Modification of https://raw.githubusercontent.com/example42/puppet-tomcat/master/templates/instance/init7-Debian.erb
# /etc/init.d/tomcat8 -- startup script for the Tomcat 8 servlet engine
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux    by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
# Modified for Tomcat8 by OhYoungJooung <wnapdlf05@gmail.com>.
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
#
### BEGIN INIT INFO
# Provides:          tomcat8-<%= @instance_name %>
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=`basename $0`
DESC="Tomcat8 servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat8-$NAME-tmp

if [ `id -u` -ne 0 ]; then
    echo "You need root privileges to run this script"
    exit 1
fi

# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
    . /etc/default/locale
    export LANG
fi

. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
    . /etc/default/rcS
fi


# The following variables can be overwritten in $DEFAULT

# Run Tomcat 8 as this user ID and group ID
TOMCAT8_USER=<%= @instance_owner %>
TOMCAT8_GROUP=<%= @instance_group %>


# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
        for jvmdir in /usr/lib/jvm/java-7-openjdk-*
        do
                if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
                then
                        OPENJDKS=$jvmdir
                fi
        done
        for jvmdir in /usr/lib/jvm/java-6-openjdk-*
        do
                if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
                then
                        OPENJDKS="${OPENJDKS} ${jvmdir}"
                fi
        done
}

OPENJDKS=""
find_openjdks
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-7-oracle"

# 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="$jdir"
    fi
done
export JAVA_HOME

# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=<%= @catalina_home %>

# Directory for per-instance configuration files and webapps
CATALINA_BASE=<%= @catalina_base %>

# Use the Java security manager? (yes/no)
TOMCAT8_SECURITY=<%= @java_security_manager %>

# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
    JAVA_OPTS="<%= @java_opts %>"
fi

# End of variables that can be overwritten in $DEFAULT

# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
    . <%= $default_File %>
fi

if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
    log_failure_msg "$NAME is not installed"
    exit 1
fi

POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"

if [ -z "$CATALINA_TMPDIR" ]; then
    CATALINA_TMPDIR="$JVM_TMP"
fi

# Set the JSP compiler if set in the tomcat8.default file
if [ -n "$JSP_COMPILER" ]; then
    JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi

SECURITY=""
if [ "$TOMCAT8_SECURITY" = "yes" ]; then
    SECURITY="-security"
fi

# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"

# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
    JSSE_HOME="${JAVA_HOME}/jre/"
fi

catalina_sh() {
    # Escape any double quotes in the value of JAVA_OPTS
    JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"

    AUTHBIND_COMMAND=""
    if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
        JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
        AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
    fi

    # Define the command to run Tomcat's catalina.sh as a daemon
    # set -a tells sh to export assigned variables to spawned shells.
    TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
        CATALINA_HOME=\"$CATALINA_HOME\"; \
        CATALINA_BASE=\"$CATALINA_BASE\"; \
        JAVA_OPTS=\"$JAVA_OPTS\"; \
        CATALINA_PID=\"$CATALINA_PID\"; \
        CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
        LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
        cd \"$CATALINA_BASE\"; \
        \"$CATALINA_SH\" $@"

    if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
        TOMCAT_SH="'$TOMCAT_SH'"
    fi

    # Run the catalina.sh script as a daemon
    set +e
    touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
    chown $TOMCAT8_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
    start-stop-daemon --start -b -u "$TOMCAT8_USER" -g "$TOMCAT8_GROUP" \
        -c "$TOMCAT8_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
        -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
    status="$?"
    set +a -e
    return $status
}

case "$1" in
  start)
    if [ -z "$JAVA_HOME" ]; then
        log_failure_msg "no JDK found - please set JAVA_HOME"
        exit 1
    fi

    if [ ! -d "$CATALINA_BASE/conf" ]; then
        log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
        exit 1
    fi

    log_daemon_msg "Starting $DESC" "$NAME"
    if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
        --user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
        >/dev/null; then

        # Regenerate POLICY_CACHE file
        umask 022
        echo "// AUTO-GENERATED FILE from /etc/tomcat8/policy.d/" \
            > "$POLICY_CACHE"
        echo ""  >> "$POLICY_CACHE"
                if [ $(ls -1 $CATALINA_BASE/conf/policy.d/ | grep ".policy$" | wc -l) -ne 0 ]; then
                  cat $CATALINA_BASE/conf/policy.d/*.policy \
                         >> "$POLICY_CACHE"
                fi

        # Remove / recreate JVM_TMP directory
        rm -rf "$JVM_TMP"
        mkdir -p "$JVM_TMP" || {
            log_failure_msg "could not create JVM temporary directory"
            exit 1
        }
        chown $TOMCAT8_USER "$JVM_TMP"

        catalina_sh start $SECURITY
        sleep 5
            if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
            --user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
            >/dev/null; then
            if [ -f "$CATALINA_PID" ]; then
                rm -f "$CATALINA_PID"
            fi
            log_end_msg 1
        else
            log_end_msg 0
        fi
    else
            log_progress_msg "(already running)"
        log_end_msg 0
    fi
    ;;
  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"

    set +e
    if [ -f "$CATALINA_PID" ]; then
        start-stop-daemon --stop --pidfile "$CATALINA_PID" \
            --user "$TOMCAT8_USER" \
            --retry=TERM/20/KILL/5 >/dev/null
        if [ $? -eq 1 ]; then
            log_progress_msg "$DESC is not running but pid file exists, cleaning up"
        elif [ $? -eq 3 ]; then
            PID="`cat $CATALINA_PID`"
            log_failure_msg "Failed to stop $NAME (pid $PID)"
            exit 1
        fi
        rm -f "$CATALINA_PID"
        rm -rf "$JVM_TMP"
    else
        log_progress_msg "(not running)"
    fi
    log_end_msg 0
    set -e
    ;;
   status)
    set +e
    start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
        --user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
        >/dev/null 2>&1
    if [ "$?" = "0" ]; then

        if [ -f "$CATALINA_PID" ]; then
            log_success_msg "$DESC is not running, but pid file exists."
            exit 1
        else
            log_success_msg "$DESC is not running."
            exit 3
        fi
    else
        log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
    fi
    set -e
        ;;
  restart|force-reload)
    if [ -f "$CATALINA_PID" ]; then
        $0 stop
        sleep 1
    fi
    $0 start
    ;;
  try-restart)
        if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
        --user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
        >/dev/null; then
        $0 start
    fi
        ;;
  *)
    log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
    exit 1
    ;;
esac

exit 0


root@puppet:/etc/puppet/modules/tomcat8/templates# cat server.xml.erb
<?xml version='1.0' encoding='utf-8'?>
<!--change
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8010" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>




No comments:

Post a Comment