diff --git a/hieradata/common.yaml b/hieradata/common.yaml index 0348e8f..bc472b4 100644 --- a/hieradata/common.yaml +++ b/hieradata/common.yaml @@ -13,3 +13,4 @@ my::packages_no_conf: - libxml2 - libxml2-dev - libxml2-utils + - links diff --git a/manifests/first.pp b/manifests/first.pp index baec4cb..8421e51 100644 --- a/manifests/first.pp +++ b/manifests/first.pp @@ -53,3 +53,10 @@ } #### Tomcat 8 +class { "tomcat8": + install_dir => '/opt/installations', + require => Exec['update-java-alternatives'], +} + +class { "probe": } + diff --git a/modules/probe/manifests/init.pp b/modules/probe/manifests/init.pp new file mode 100644 index 0000000..426ad56 --- /dev/null +++ b/modules/probe/manifests/init.pp @@ -0,0 +1,11 @@ +class probe( + $source_dir = hiera('probe::source_dir', '/opt/sources' ), + $tomcat_webapps = hiera('probe::tomcat_webapps', '/var/lib/tomcat8/webapps'), + $ensure = 'installed', +){ + exec{'install_probe': + command => "sudo ${::settings::modulepath}/scripts/probe.sh $source_dir $tomcat_webapps", + creates => "$tomcat_webapps/probe.war", + require => Class["tomcat8"], + } +} diff --git a/modules/scripts/probe.sh b/modules/scripts/probe.sh new file mode 100644 index 0000000..f5f9026 --- /dev/null +++ b/modules/scripts/probe.sh @@ -0,0 +1,10 @@ +#!/bin/bash +SOURCE=$1 +TOMCAT_WEBAPPS=$3 + +pushd $SOURCE +git clone https://github.com/psi-probe/psi-probe && pushd psi-probe +mvn package +cp web/target/probe.war $TOMCAT_WEBAPPS/ +popd +popd diff --git a/modules/tomcat8/manifests/init.pp b/modules/tomcat8/manifests/init.pp index 4f8734a..f22724b 100644 --- a/modules/tomcat8/manifests/init.pp +++ b/modules/tomcat8/manifests/init.pp @@ -3,6 +3,8 @@ $ensure = 'installed', $from = hiera('tomcat8::from'), $keypath = hiera('tomcat8::keypath'), + $xmx = hiera('tomcat8::xmx', '4096M'), + $xms = hiera('tomcat8::xms', '1024M'), ) { if $ensure == 'installed' { @@ -25,7 +27,7 @@ creates => "${install_dir}/${installerFilename}", command => "wget -c --no-cookies --no-check-certificate \"${downloadURI}\" -O ${installerFilename}", timeout => 600, - require => Package['wget'], + require => [ Package['wget'], User['tomcat'] ], } file { "${install_dir}/${installerFilename}": @@ -48,38 +50,67 @@ require => Exec['get_tomcat'], } + file { "${install_dir}/${dirname}": + require => Exec['extract_tomcat'], + ensure => directory, + recurse => true, + owner => 'tomcat', + } + file { "${install_dir}/tomcat8": ensure => link, target => "${install_dir}/${dirname}", require => Exec['extract_tomcat'], + owner => 'tomcat', } $var_dirs = ["/var/lib/tomcat8", "/var/lib/tomcat8/temp", "/var/lib/tomcat8/webapps", "/var/log/tomcat8", "/var/cache/tomcat8", "/var/cache/tomcat8/Catalina"] file {$var_dirs: ensure => directory, + recurse => true, + owner => 'tomcat', } file { '/var/lib/tomcat8/logs': ensure => link, target => '/var/log/tomcat8', + owner => 'tomcat', } file { '/var/lib/tomcat8/work': ensure => link, target => '/var/cache/tomcat8', + owner => 'tomcat', } file { '/var/lib/tomcat8/conf': ensure => link, target => "${install_dir}/tomcat8/conf", + owner => 'tomcat', } file{ '/var/lib/tomcat8/work/catalina.policy': ensure => file, source => 'puppet:///modules/tomcat8/catalina.policy', + owner => 'tomcat', } exec { 'scp_policy.d': command => "scp -r -i ${keypath} -o StrictHostKeyChecking=no ${from}:/opt/tomcat8/conf/policy.d ${install_dir}/tomcat8/conf/", creates => "${install_dir}/tomcat8/conf/policy.d", require => File["${install_dir}/tomcat8"], } + exec { 'scp_config': + command => "scp -r -i ${keypath} -o StrictHostKeyChecking=no ${from}:/opt/tomcat8/conf/\\{server.xml, tomcat-users.xml\\} ${install_dir}/tomcat8/conf/", + unless => "grep \"admin\" ${install_dir}/tomcat8/conf/tomcat_users.xml", + require => File["${install_dir}/tomcat8"], + } + file { ["${install_dir}/tomcat8/conf/server.xml","${install_dir}/tomcat8/conf/tomcat-users.xml"]: + owner => 'tomcat', + require => Exec['scp_config'], + } + file { "${install_dir}/tomcat8/conf/policy.d": + require => Exec['scp_policy.d'], + ensure => directory, + recurse => true, + owner => 'tomcat', + } exec { 'scp_init_script': command => "scp -r -i ${keypath} -o StrictHostKeyChecking=no ${from}:/etc/init.d/tomcat8 /etc/init.d/", creates => "/etc/init.d/tomcat8", @@ -87,34 +118,24 @@ notify => Exec['cleanup_init'] } exec {'cleanup_init': - command => "sed -i -e \"s/tomcat6/tomcat/g\" -e \"s#/opt/\$NAME#${install_dir}/tomcat8#g\" /etc/init.d/tomcat8" + command => "sed -i -e \"s/tomcat6/tomcat/g\" -e \"s#^CATALINA_HOME=.*#CATALINA_HOME=${install_dir}/tomcat8#\" -e \"s#^JDK_DIRS=.*#JDK_DIRS=$(dirname $(readlink -f $(which javac) | sed -e 's#bin/##'))#\" -e \"s#-Xmx[0-9]*[MmGg]#-Xmx${xmx}#\" -e \"s#-Xms[0-9]*[MmGg]#-Xms${xms}#\" /etc/init.d/tomcat8", + before => Service["tomcat8"], + } + user { "tomcat": + ensure => present, + managehome => true, + shell => '/bin/bash', + } + service { "tomcat8": + ensure => running, + enable => true, + require => Exec['scp_init_script'], } - #user { "tomcat": - # ensure => present, - # managehome => true, - # shell => '/bin/bash', - #} - #service { "tomcat8": - # ensure => running, - # enable => true, - # reguire => Exec['scp_init_scrip'], - #} #probe +#server + users + context #native -#user on files - - # Ensure that files belong to tomcat - #file {$java_home: - # recurse => true, - # owner => root, - # group => root, - # subscribe => Exec['extract_tomcat'], - #} - # Set links depending on osfamily or operating system fact } } - -class { 'tomcat8':}