Permalink
Browse files

install tomcat 7

This uses a slightly adapted version of https://forge.puppetlabs.com/llehmijo/tomcat7_rhel
no configuration changes on the tomcat yet, binds only to localhost etc.
  • Loading branch information...
1 parent 17d8396 commit 9f4d9bea92ae22b9dcebb6bfbe9734e4eabe239f @Xylakant Xylakant committed Feb 2, 2013
@@ -67,10 +67,11 @@
include projects
include installrvm
include java::jdk
+ include tomcat7
class { requirements: stage => 'requirementsstage' }
- Class['java::jdk'] -> Class['installrvm'] -> Class['projects']
+ Class['java::jdk'] -> Class['tomcat7'] -> Class['installrvm'] -> Class['projects']
}
# start and set up everything
@@ -0,0 +1,19 @@
+Copyright (C) 2013 Lauri Lehmijoki
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,13 @@
+class tomcat7 {
+ include tomcat7::jpackage_repo
+
+ package { "tomcat7":
+ ensure => installed,
+ require => [Yumrepo['jpackage']]
+ }
+
+ service { "tomcat7":
+ ensure => started,
+ require => [Package['tomcat7']]
+ }
+}
@@ -0,0 +1,9 @@
+class tomcat7::jpackage_repo {
+ yumrepo { "jpackage":
+ descr => "JPackage project",
+ baseurl => "http://mirrors.dotsrc.org/jpackage/6.0/generic/free/",
+ enabled => 1,
+ gpgcheck => 1,
+ gpgkey => "http://www.jpackage.org/jpackage.asc",
+ }
+}
@@ -0,0 +1,85 @@
+define tomcat7::tomcat_application(
+ $application_name = $title,
+ $application_root,
+ $tomcat_user,
+ $tomcat_port,
+ $tomcat_control_port = ($tomcat_port + 1000),
+ $jvm_envs,
+ $tomcat_manager = false,
+ $tomcat_admin_user = "tomcat",
+ $tomcat_admin_password = "s3cr3t",
+ $jmx_registry_port = 10052,
+ $jmx_server_port = 10051) {
+ include tomcat7
+
+ $application_dir = "$application_root/$application_name"
+ $tomcat_log = "$application_dir/logs/catalina.out"
+ $catalina_home = "/usr/share/tomcat7"
+
+ File {
+ before => Service["$application_name"]
+ }
+
+ file { [
+ "$application_dir/bin","$application_dir/conf","$application_dir/temp",
+ "$application_dir/work", "$application_dir/logs",
+ "$application_dir/webapps", "$application_dir/conf/Catalina",
+ "$application_dir/conf/Catalina/localhost"]:
+ ensure => directory,
+ owner => $tomcat_user,
+ group => $tomcat_user
+ }
+
+ file { "$application_dir":
+ ensure => directory
+ }
+
+ service { "$application_name":
+ ensure => running,
+ enable => true,
+ hasstatus => true,
+ require => Package['tomcat7']
+ }
+
+ file { "/etc/init.d/$application_name":
+ ensure => link,
+ target => "/etc/init.d/tomcat7",
+ require => Package['tomcat7']
+ }
+
+ if $tomcat_manager == true {
+ tomcat7::tomcat_manager { "Install Tomcat Manager for $application_name":
+ tomcat_admin_user => $tomcat_admin_user,
+ tomcat_admin_password => $tomcat_admin_password,
+ tomcat_user => $tomcat_user,
+ application_dir => $application_dir,
+ application_name => $application_name,
+ tomcat_port => $tomcat_port
+ }
+ }
+
+ file { "$application_dir/conf/web.xml":
+ ensure => link,
+ target => "$catalina_home/conf/web.xml",
+ }
+
+ file { "/etc/sysconfig/$application_name":
+ content => template("tomcat7/etc/sysconfig/tomcat7.erb")
+ }
+
+ file { "$application_dir/conf/server.xml":
+ content => template("tomcat7/server.xml.erb")
+ }
+
+ file { "/etc/logrotate.d/$application_name":
+ content => template("tomcat7/etc/logrotate.d/tomcat7.erb")
+ }
+
+ file { "$application_dir/bin/run_smoke_test.sh":
+ content => template("tomcat7/run_smoke_test.sh.erb"),
+ owner => "$tomcat_user",
+ group => "$tomcat_user",
+ mode => 0744,
+ require => File["$application_dir/bin"]
+ }
+}
@@ -0,0 +1,58 @@
+define tomcat7::tomcat_manager(
+ $tomcat_admin_user,
+ $tomcat_admin_password,
+ $tomcat_user,
+ $application_dir,
+ $application_name,
+ $tomcat_port) {
+ require tomcat7::tomcat7_manager_package
+
+ file { "$application_dir/conf/Catalina/localhost/manager.xml":
+ content => template("tomcat7/manager.xml.erb"),
+ notify => Service["$application_name"]
+ }
+
+ file { "$application_dir/conf/tomcat-users.xml":
+ content => template("tomcat7/tomcat-users.xml.erb"),
+ notify => Service["$application_name"]
+ }
+
+ file { "$application_dir/bin/deploy_with_tomcat_manager.sh":
+ content => template("tomcat7/deploy_with_tomcat_manager.sh.erb"),
+ owner => "$tomcat_user",
+ group => "$tomcat_user",
+ mode => 0740,
+ require => File["$application_dir/bin"]
+ }
+
+ file { "$application_dir/bin/check_memory_leaks.sh":
+ content => template("tomcat7/check_memory_leaks.sh.erb"),
+ owner => "$tomcat_user",
+ group => "$tomcat_user",
+ mode => 0740,
+ require => File["$application_dir/bin"]
+ }
+
+ file { "$application_dir/bin/list-applications.sh":
+ content => template("tomcat7/list-applications.sh.erb"),
+ owner => "$tomcat_user",
+ group => "$tomcat_user",
+ mode => 0740,
+ require => File["$application_dir/bin"]
+ }
+
+ file { "$application_dir/bin/undeploy_with_tomcat_manager.sh":
+ content => template("tomcat7/undeploy_with_tomcat_manager.sh.erb"),
+ owner => "$tomcat_user",
+ group => "$tomcat_user",
+ mode => 0740,
+ require => File["$application_dir/bin"]
+ }
+}
+
+class tomcat7::tomcat7_manager_package {
+ package { "tomcat7-admin-webapps":
+ ensure => installed,
+ require => [Package['tomcat7'], Yumrepo['jpackage']]
+ }
+}
@@ -0,0 +1,4 @@
+#!/bin/bash -e
+
+curl -4 -u <%=tomcat_admin_user%>:<%=tomcat_admin_password%> "http://localhost:<%=tomcat_port%>/manager/text/findleaks?statusLine=true"
+
@@ -0,0 +1,25 @@
+#!/bin/bash -e
+
+WAR_FILE=$1
+VERSION=$2
+
+
+if [ -z "$WAR_FILE" ]; then
+ echo "Usage: deploy_with_tomcat_manager.sh [<full path to local .war] [VERSION TO DEPLOY (optional)]"
+ exit 1
+fi
+
+if [ ! -f "$WAR_FILE" ];
+then
+ echo "File $WAR_FILE was not found!"
+ exit 1
+fi
+
+VERSIONSTRING=""
+if [ ! -z "$VERSION" ]; then
+ echo "Using parallel deployment, deploying version $VERSION"
+ VERSIONSTRING="&version=$VERSION"
+fi
+
+
+curl -4 -u <%=tomcat_admin_user%>:<%=tomcat_admin_password%> "http://localhost:<%=tomcat_port%>/manager/text/deploy?path=/&tag=<%=application_name%>&war=file:$WAR_FILE&update=true$VERSIONSTRING"
@@ -0,0 +1,17 @@
+<%= tomcat_log %> {
+ copytruncate
+ weekly
+ rotate 52
+ compress
+ missingok
+ create 0644 <%= tomcat_user %> <%= tomcat_user %>
+}
+
+<%= application_dir %>/logs/*access_log*.txt {
+ copytruncate
+ daily
+ rotate 52
+ compress
+ missingok
+ create 0644 <%= tomcat_user %> <%= tomcat_user %>
+}
@@ -0,0 +1,30 @@
+# Where your tomcat installation lives
+CATALINA_HOME="<%= catalina_home %>"
+CATALINA_BASE="<%= application_dir%>"
+CATALINA_TMPDIR="$CATALINA_BASE/temp"
+
+JVM_OPTS="<%= jvm_envs %>"
+
+JAVA_OPTS="${JAVA_OPTS} ${JVM_OPTS}"
+
+# What user should run tomcat
+TOMCAT_USER="<%= tomcat_user %>"
+
+TOMCAT_LOG=<%= tomcat_log %>
+
+# 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="10"
+
+# 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/<%= application_name %>.pid"
+
+TOMCAT_CFG=/etc/sysconfig/<%= application_name %>
@@ -0,0 +1,3 @@
+#!/bin/bash -e
+
+curl -4 -u <%=tomcat_admin_user%>:<%=tomcat_admin_password%> "http://localhost:<%=tomcat_port%>/manager/text/list"
@@ -0,0 +1,4 @@
+<!--<?xml version="1.0" encoding="UTF-8"?> -->
+<Context path="/manager" docBase="/var/lib/tomcat7/webapps/manager" antiResourceLocking="false" privileged="true">
+ <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1|0:0:0:0:0:0:0:1" deny="" />
+</Context>
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+COUNTER=0
+while curl -L -s -o /dev/null -w "%{http_code}" localhost:<%=tomcat_port%> | grep -v 200; do
+ echo Waiting for <%=application_name%> to respond...
+ let COUNTER=COUNTER+1
+ if [ $COUNTER -ge 40 ]; then
+ break
+ fi
+ sleep 2
+done
+
+curl -L -s -o /dev/null -w "%{http_code}" localhost:<%=tomcat_port%> | grep 200 > /dev/null
+if [[ "$?" -eq 0 ]]; then
+ echo "Smoke test on <%=application_name%> succeeded"
+ exit 0
+else
+ echo "Smoke test on <%=application_name%> failed"
+ exit 1
+fi
Oops, something went wrong.

0 comments on commit 9f4d9be

Please sign in to comment.