diff --git a/CHANGELOG.md b/CHANGELOG.md index 7507c2b..f0a4c6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +###0.5.0 + +* Support SuSE OS family +* Configures instance admin webapps properly when installed from archive +* Does not uninstall unrequired libraries anymore (native, log4j) +* Improve warning logging +* Cleanup + ###0.4.1 * Document missing parameter `installation_support` diff --git a/README.md b/README.md index 8b63b3f..c5a1df7 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,14 @@ 1. [Overview](#overview) 2. [Module Description](#module-description) 3. [Setup](#setup) + * [A couple of examples](#a-couple-of-examples) 4. [Usage](#usage) - * [Class: tomcat](#class-tomcat) - * [Define: tomcat::instance](#define-tomcatinstance) - * [Common parameters](#common-parameters) - * [Define: tomcat::userdb_entry](#define-tomcatuserdb_entry) -5. [Limitations](#limitations) -6. [To Do](#to-do) + * [Classes and Defined Types](#classes-and-defined-types) + * [Class: tomcat](#class-tomcat) + * [Define: tomcat::instance](#define-tomcatinstance) + * [Common parameters](#common-parameters) + * [Define: tomcat::userdb_entry](#define-tomcatuserdb_entry) +5. [To Do](#to-do) ##Overview @@ -19,7 +20,7 @@ The tomcat module installs and configures Apache Tomcat instances from either th ##Module description -This module will install the desired version of the Apache Tomcat Web Application Container from almost any possible source, including the repositories available on the target system (distribution repositories or third-party sources like [JPackage](http://www.jpackage.org) and [EPEL](https://fedoraproject.org/wiki/EPEL) +This module will install the desired version of the Apache Tomcat Web Application Container from almost any possible source, including the repositories available on the target system (distribution repositories or third-party sources like [JPackage](http://www.jpackage.org) and [EPEL](https://fedoraproject.org/wiki/EPEL)) A long list of parameters permit a fine-tuning of the server and the JVM. It is for example possible to configure admin applications, install extra tomcat libraries, configure log4j as the standard logger, or enable the remote JMX listener. The creation of individual instances is also supported via a custom type. @@ -49,6 +50,25 @@ class { '::tomcat': } ``` +Disable default instance and setup 2 individual instances + +```puppet +class { '::tomcat': + service_ensure => 'stopped', + service_enable => false +} +tomcat::instance { 'instance1': + control_port => 8005, + http_port => 8080, + ajp_connector => false +} +tomcat::instance { 'instance2': + control_port => 8006, + http_port => 8081, + manage_firewall => true +} +``` + Use a non-default JVM and run it with custom options ```puppet @@ -107,6 +127,7 @@ Use log4j for Tomcat internal logging and provide a custom XML configuration fil class { '::tomcat': … log4j => true, + log4j_enable => true, log4j_conf_type => 'xml', log4j_conf_source => 'puppet:///modules/my_configs/tomcat_log4j.xml' } @@ -128,36 +149,15 @@ class { '::tomcat': } ``` -Disable default instance and setup 2 individual instances - -```puppet -class { '::tomcat': - service_ensure => 'stopped', - service_enable => false, - log4j => true -} -tomcat::instance { 'instance1': - control_port => 8005, - http_port => 8080, - ajp_connector => false, - java_home => '/usr/java/jre1.7.0_65', - java_opts => ['-server', '-Xms256m', '-Xmx2048m', '-XX:+UseConcMarkSweepGC'], -} -tomcat::instance { 'instance2': - control_port => 8006, - http_port => 8081, - log4j_enable => true, - manage_firewall => true -} -``` - ##Usage This module distinguishes two different contexts: * global: default instance and global libraries * instance: individual tomcat instance -Both contexts have a lot of parameters in common +Both contexts share most of their parameters. + +###Classes and Defined Types ####Class: `tomcat` @@ -340,13 +340,8 @@ User password (string) #####`roles` User roles (array of strings) -##Limitations - -* Only supports RedHat and Debian variants/derivatives (for now) - ##To Do -* Support SuSE Linux * Proper startup script for distributions which do not have systemd * Parameters validation diff --git a/files/instance/systemd_unit.erb b/files/instance/systemd_unit.erb deleted file mode 100644 index f7d9117..0000000 --- a/files/instance/systemd_unit.erb +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Apache Tomcat Web Application Container -After=syslog.target network.target - -[Service] -Type=forking -ExecStart=/usr/sbin/tomcat-sysd start -ExecStop=/usr/sbin/tomcat-sysd stop -SuccessExitStatus=143 -User=tomcat -Group=tomcat -EnvironmentFile=-/etc/sysconfig/ - - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/manifests/config.pp b/manifests/config.pp index ea988cf..7b4a845 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -8,7 +8,7 @@ # generate and manage server configuration # Template uses: - # - + #- file { 'tomcat server configuration': path => "${::tomcat::catalina_base_real}/conf/server.xml", content => template("${module_name}/common/server.xml.erb"), @@ -20,20 +20,20 @@ # generate and manage global parameters # Template uses: - # - + #- # note: defining the exact same parameters in two files may seem awkward, # but it avoids the randomness observed in some releases due to buggy startup scripts - file { - 'tomcat environment variables': - path => $::tomcat::config_path_real, - content => template("${module_name}/common/setenv.erb"), - owner => $::tomcat::tomcat_user_real, - group => $::tomcat::tomcat_group_real, - mode => '0644', - notify => Service[$::tomcat::service_name_real] + file { 'tomcat environment variables': + path => $::tomcat::config_path_real, + content => template("${module_name}/common/setenv.erb"), + owner => $::tomcat::tomcat_user_real, + group => $::tomcat::tomcat_group_real, + mode => '0644', + notify => Service[$::tomcat::service_name_real] } if $::osfamily == 'RedHat' { + # make sure system variables are in the right place file { 'tomcat default variables': path => "${::tomcat::catalina_base_real}/conf/${::tomcat::service_name_real}.conf", content => "# See ${::tomcat::config_path_real}" diff --git a/manifests/init.pp b/manifests/init.pp index 8b76d56..1a36587 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -188,8 +188,8 @@ if $admin_webapps_package_name == undef { $admin_webapps_package_name_real = $::osfamily ? { - 'RedHat' => "${package_name}-admin-webapps", - default => "${package_name}-admin" + 'Debian' => "${package_name}-admin", + default => "${package_name}-admin-webapps" } } else { $admin_webapps_package_name_real = $admin_webapps_package_name } @@ -206,8 +206,8 @@ case $installation_support { 'package' : { $catalina_base_real = $::osfamily ? { - 'RedHat' => $catalina_home_real, - default => "/var/lib/${service_name_real}" + 'Debian' => "/var/lib/${service_name_real}", + default => $catalina_home_real } } default : { $catalina_base_real = $catalina_home_real @@ -251,8 +251,9 @@ case $installation_support { 'package' : { $config_path_real = $::osfamily ? { - 'RedHat' => "/etc/sysconfig/${service_name_real}", - default => "/etc/default/${service_name_real}" + 'Debian' => "/etc/default/${service_name_real}", + 'Suse' => "/etc/${service_name_real}/${service_name_real}.conf", + default => "/etc/sysconfig/${service_name_real}" } } default : { $config_path_real = "${catalina_base_real}/bin/setenv.sh" @@ -281,8 +282,8 @@ if $tomcat_user == undef { $tomcat_user_real = $::osfamily ? { - 'RedHat' => 'tomcat', - default => $package_name + 'Debian' => $package_name, + default => 'tomcat' } } else { $tomcat_user_real = $tomcat_user } diff --git a/manifests/install.pp b/manifests/install.pp index 2fc65f5..b343fe8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -14,34 +14,18 @@ } # tomcat native library - $ensure_native_package = $::tomcat::tomcat_native ? { - true => 'present', - default => 'absent' - } - package { 'tomcat native library': - ensure => $ensure_native_package, - name => $::tomcat::tomcat_native_package_name + if $::tomcat::tomcat_native { + package { 'tomcat native library': + ensure => present, + name => $::tomcat::tomcat_native_package_name + } } # log4j library - $ensure_log4j_package = $::tomcat::log4j ? { - true => 'present', - default => 'absent' - } - package { 'tomcat log4j library': - ensure => $ensure_log4j_package, - name => $::tomcat::log4j_package_name - } - - # install admin webapps - if $tomcat::installation_support == 'package' { - $ensure_manager_package = $::tomcat::admin_webapps ? { - true => 'present', - default => 'absent' - } - package { 'tomcat admin webapps': - ensure => $ensure_manager_package, - name => $::tomcat::admin_webapps_package_name_real + if $::tomcat::log4j { + package { 'tomcat log4j library': + ensure => present, + name => $::tomcat::log4j_package_name } } } \ No newline at end of file diff --git a/manifests/install/archive.pp b/manifests/install/archive.pp index 947cef7..f6cb208 100644 --- a/manifests/install/archive.pp +++ b/manifests/install/archive.pp @@ -43,4 +43,9 @@ ensure => directory, path => "/var/log/${::tomcat::service_name_real}" } + + # warn if admin webapps were selected for installation + if $::tomcat::admin_webapps { + warning("tomcat archives always contain admin webapps, ignoring parameter 'admin_webapps'") + } } \ No newline at end of file diff --git a/manifests/install/package.pp b/manifests/install/package.pp index aedcc8f..0591a6b 100644 --- a/manifests/install/package.pp +++ b/manifests/install/package.pp @@ -14,8 +14,16 @@ name => $::tomcat::package_name } + # install admin webapps + if $::tomcat::admin_webapps { + package { 'tomcat admin webapps': + ensure => present, + name => $::tomcat::admin_webapps_package_name_real + } + } + # fix broken status check in some tomcat init scripts - if $::osfamily == 'RedHat' and $::operatingsystemmajrelease < 7 and $::tomcat::installation_support == 'package' { + if $::osfamily == 'RedHat' and $::operatingsystemmajrelease < 7 { file_line { 'fix broken tomcat init script': path => "/etc/init.d/${::tomcat::service_name_real}", line => " pid=\"$(/usr/bin/pgrep -d , -u \${TOMCAT_USER} -G \${TOMCAT_USER} -f Dcatalina.base=\${CATALINA_BASE})\"", diff --git a/manifests/instance.pp b/manifests/instance.pp index 9a1780c..82d6a7a 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -195,8 +195,8 @@ case $::tomcat::installation_support { 'package' : { $config_path_real = $::osfamily ? { - 'RedHat' => "/etc/sysconfig/${service_name_real}", - default => "/etc/default/${service_name_real}" + 'Debian' => "/etc/default/${service_name_real}", + default => "/etc/sysconfig/${service_name_real}" } } default : { $config_path_real = "${catalina_base_real}/bin/setenv.sh" @@ -232,7 +232,7 @@ } # should we force download extras libs? - if $log4j_enable or $jmx_listener { + if ($log4j_enable or $jmx_listener) and !$::tomcat::enable_extras_real { $enable_extras_real = true } else { $enable_extras_real = $enable_extras @@ -242,6 +242,11 @@ # service # # --------# + if $::operatingsystem == 'OpenSuSE' { + Service { # not explicit on OpenSuSE + provider => systemd } + } + case $::tomcat::installation_support { 'package' : { # manage startup script/unit @@ -253,12 +258,19 @@ mode => '0755', content => template("${module_name}/instance/tomcat${::tomcat::maj_version}_init_deb.erb"); } + } elsif $::operatingsystem == 'OpenSuSE' { + file { "${service_name_real} service unit": + path => "/usr/lib/systemd/system/${service_name_real}.service", + owner => 'root', + group => 'root', + content => template("${module_name}/instance/systemd_unit_suse.erb") + } } elsif $::operatingsystem == 'Fedora' or ($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora' and $::operatingsystemmajrelease >= 7) { file { "${service_name_real} service unit": path => "/usr/lib/systemd/system/${service_name_real}.service", owner => 'root', group => 'root', - content => template("${module_name}/instance/systemd_unit.erb") + content => template("${module_name}/instance/systemd_unit_rhel.erb") } } else { file { "${service_name_real} service unit": @@ -276,13 +288,24 @@ require => File["${service_name_real} service unit"] } } + # archive default : { - if $::operatingsystem == 'Fedora' or ($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora' and $::operatingsystemmajrelease >= 7) { - file { "${service_name_real} service unit": - path => "/usr/lib/systemd/system/${service_name_real}.service", - owner => 'root', - group => 'root', - content => template("${module_name}/instance/systemd_unit.erb") + # systemd is prefered if supported + if $::tomcat::params::systemd { + if $::operatingsystem == 'OpenSuSE' { + file { "${service_name_real} service unit": + path => "/usr/lib/systemd/system/${service_name_real}.service", + owner => 'root', + group => 'root', + content => template("${module_name}/instance/systemd_unit_suse.erb") + } + } else { # RHEL 7+ or Fedora + file { "${service_name_real} service unit": + path => "/usr/lib/systemd/system/${service_name_real}.service", + owner => 'root', + group => 'root', + content => template("${module_name}/instance/systemd_unit_rhel.erb") + } } service { $service_name_real: @@ -290,7 +313,8 @@ enable => $service_enable, require => File["${service_name_real} service unit"]; } - } else { # temporary solution until a proper init script is included + # temporary solution until a proper init script is included + } else { $catalina_script = "${catalina_home_real}/bin/catalina.sh" $start_command = "export CATALINA_BASE=${catalina_base_real}; /bin/su ${::tomcat::tomcat_user_real} -s /bin/bash -c '${catalina_script} start'" $stop_command = "export CATALINA_BASE=${catalina_base_real}; /bin/su ${::tomcat::tomcat_user_real} -s /bin/bash -c '${catalina_script} stop'" @@ -300,7 +324,7 @@ service { $service_name_real: ensure => $service_ensure, enable => $service_enable, - provider => 'base', + provider => base, start => $start_command, stop => $stop_command, status => $status_command @@ -408,13 +432,6 @@ notify => Service[$service_name_real] } - if $::osfamily == 'RedHat' { - file { "instance ${name} default variables": - path => "${catalina_base_real}/conf/${service_name_real}.conf", - content => "# See ${config_path_real}" - } - } - # ------# # users # # ------# @@ -441,7 +458,7 @@ } # configure authorized access - unless !$::tomcat::create_default_admin { + unless !$create_default_admin { ::tomcat::userdb_entry { "instance ${name} ${::tomcat::admin_user}": database => "instance ${name} UserDatabase", username => $admin_user, @@ -455,9 +472,15 @@ # --------------# if $admin_webapps { # generate OS-specific variables - $admin_webapps_path = $::osfamily ? { - 'RedHat' => "\${catalina.home}/webapps", - default => "/usr/share/${::tomcat::admin_webapps_package_name_real}" + case $::tomcat::installation_support { + 'package' : { + $admin_webapps_path = $::osfamily ? { + 'Debian' => "/usr/share/${::tomcat::admin_webapps_package_name_real}", + default => "\${catalina.home}/webapps" + } } + default : { + $admin_webapps_path = "\${catalina.home}/webapps" + } } file { "instance ${name} Catalina dir": @@ -487,15 +510,17 @@ if $log4j_enable { # warn user if log4j is not installed unless $::tomcat::log4j { - warning('Logging with log4j will not work unless the log4j library is installed') + warning("instance ${name}: logging with log4j will not work unless the log4j library is installed") } # no need to duplicate libraries if enabled globally - unless $::tomcat::log4j_enable { + if $::tomcat::log4j_enable { + warning("instance ${name}: log4j is already enabled globally, ignoring parameter 'log4j_enable'") + } else { # generate OS-specific variables $log4j_path = $::osfamily ? { - 'RedHat' => '/usr/share/java/log4j.jar', - default => '/usr/share/java/log4j-1.2.jar' + 'Debian' => '/usr/share/java/log4j-1.2.jar', + default => '/usr/share/java/log4j.jar' } file { "instance ${name} log4j library": @@ -552,62 +577,66 @@ # extras # # -------# - if $enable_extras_real and !$::tomcat::enable_extras_real { # no need to duplicate libraries if enabled globally - Staging::File { - require => File["instance ${name} extras directory"], - notify => Service[$service_name_real] - } + if $enable_extras_real { + if $::tomcat::enable_extras_real { # no need to duplicate libraries if enabled globally + warning('extra libraries already enabled globally, ignoring parameter \'enable_extras\'') + } else { + Staging::File { + require => File["instance ${name} extras directory"], + notify => Service[$service_name_real] + } - staging::file { - "instance ${name} catalina-jmx-remote.jar": - target => "${catalina_base_real}/lib/extras/catalina-jmx-remote-${::tomcat::version}.jar", - source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/catalina-jmx-remote.jar" - ; - - "instance ${name} catalina-ws.jar": - target => "${catalina_base_real}/lib/extras/catalina-ws-${::tomcat::version}.jar", - source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/catalina-ws.jar" - ; - - "instance ${name} tomcat-juli-adapters.jar": - target => "${catalina_base_real}/lib/extras/tomcat-juli-adapters-${::tomcat::version}.jar", - source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/tomcat-juli-adapters.jar" - ; - - "instance ${name} tomcat-juli-extras.jar": - target => "${catalina_base_real}/lib/extras/tomcat-juli-extras-${::tomcat::version}.jar", - source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/tomcat-juli.jar" - } + staging::file { + "instance ${name} catalina-jmx-remote.jar": + target => "${catalina_base_real}/lib/extras/catalina-jmx-remote-${::tomcat::version}.jar", + source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/catalina-jmx-remote.jar" + ; + + "instance ${name} catalina-ws.jar": + target => "${catalina_base_real}/lib/extras/catalina-ws-${::tomcat::version}.jar", + source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/catalina-ws.jar" + ; + + "instance ${name} tomcat-juli-adapters.jar": + target => "${catalina_base_real}/lib/extras/tomcat-juli-adapters-${::tomcat::version}.jar", + source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/tomcat-juli-adapters.jar" + ; + + "instance ${name} tomcat-juli-extras.jar": + target => "${catalina_base_real}/lib/extras/tomcat-juli-extras-${::tomcat::version}.jar", + source => "http://archive.apache.org/dist/tomcat/tomcat-${::tomcat::maj_version}/v${::tomcat::version}/bin/extras/tomcat-juli.jar" + } - file { - "instance ${name} extras directory": - ensure => directory, - path => "${catalina_base_real}/lib/extras"; + file { + "instance ${name} extras directory": + ensure => directory, + path => "${catalina_base_real}/lib/extras"; - "instance ${name} tomcat-juli.jar": - ensure => link, - path => "${catalina_base_real}/bin/tomcat-juli.jar", - target => "${catalina_base_real}/lib/tomcat-juli-extras.jar"; + "instance ${name} tomcat-juli.jar": + ensure => link, + path => "${catalina_base_real}/bin/tomcat-juli.jar", + target => "${catalina_base_real}/lib/tomcat-juli-extras.jar"; - "instance ${name} catalina-jmx-remote.jar": - ensure => link, - path => "${catalina_base_real}/lib/catalina-jmx-remote.jar", - target => "extras/catalina-jmx-remote-${::tomcat::version}.jar"; + "instance ${name} catalina-jmx-remote.jar": + ensure => link, + path => "${catalina_base_real}/lib/catalina-jmx-remote.jar", + target => "extras/catalina-jmx-remote-${::tomcat::version}.jar"; - "instance ${name} catalina-ws.jar": - ensure => link, - path => "${catalina_base_real}/lib/catalina-ws.jar", - target => "extras/catalina-ws-${::tomcat::version}.jar"; + "instance ${name} catalina-ws.jar": + ensure => link, + path => "${catalina_base_real}/lib/catalina-ws.jar", + target => "extras/catalina-ws-${::tomcat::version}.jar"; - "instance ${name} tomcat-juli-adapters.jar": - ensure => link, - path => "${catalina_base_real}/lib/tomcat-juli-adapters.jar", - target => "extras/tomcat-juli-adapters-${::tomcat::version}.jar"; + "instance ${name} tomcat-juli-adapters.jar": + ensure => link, + path => "${catalina_base_real}/lib/tomcat-juli-adapters.jar", + target => "extras/tomcat-juli-adapters-${::tomcat::version}.jar"; - "instance ${name} tomcat-juli-extras.jar": - ensure => link, - path => "${catalina_base_real}/lib/tomcat-juli-extras.jar", - target => "extras/tomcat-juli-extras-${::tomcat::version}.jar" + "instance ${name} tomcat-juli-extras.jar": + ensure => link, + path => "${catalina_base_real}/lib/tomcat-juli-extras.jar", + target => "extras/tomcat-juli-extras-${::tomcat::version}.jar" + } } } diff --git a/manifests/log4j.pp b/manifests/log4j.pp index f41dca0..28308cf 100644 --- a/manifests/log4j.pp +++ b/manifests/log4j.pp @@ -13,8 +13,8 @@ # generate OS-specific variables $log4j_path = $::osfamily ? { - 'RedHat' => '/usr/share/java/log4j.jar', - default => '/usr/share/java/log4j-1.2.jar' + 'Debian' => '/usr/share/java/log4j-1.2.jar', + default => '/usr/share/java/log4j.jar' } file { 'global log4j library': diff --git a/manifests/params.pp b/manifests/params.pp index 85b7911..4e1fcf4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -44,22 +44,25 @@ fail("Unsupported OS version ${::operatingsystemmajrelease}") } } + $systemd = true } default : { case $::operatingsystemmajrelease { '7' : { $version = '7.0.42' $package_name = 'tomcat' + $systemd = true } '6' : { $version = '6.0.24' $package_name = 'tomcat6' - # epel + # = epel repo = # $version = '7.0.33' # $package_name = 'tomcat' - # jpackage6 + # = jpackage6 repo = # $version = '7.0.54' # $package_name = 'tomcat7' + $systemd = false } default : { fail("Unsupported OS version ${::operatingsystemmajrelease}") @@ -70,6 +73,59 @@ $tomcat_native_package_name = 'tomcat-native' $log4j_package_name = 'log4j' } + 'Suse' : { + case $::operatingsystem { + 'OpenSuSE' : { + case $::operatingsystemrelease { + '12.3' : { + $version = '7.0.35' + $package_name = 'tomcat' + # = JAVA repo = + # $version = '7.0.55' + # $package_name = 'tomcat' + } + '13.1' : { + $version = '7.0.42' + $package_name = 'tomcat' + # = JAVA repo = + # $version = '7.0.55' + # $package_name = 'tomcat' + } + '13.2' : { + $version = '7.0.55' + $package_name = 'tomcat' + # = JAVA repo = + # $version = '7.0.55' + # $package_name = 'tomcat' + } + default : { + fail("Unsupported OS version ${::operatingsystemrelease}") + } + } + $systemd = true + } + /^(SLES|SLED|SuSE)$/ : { + case $::operatingsystemrelease { + /^11\.[23]$/ : { + $version = '6.0.18' + $package_name = 'tomcat6' + } + '12.0' : { + $version = '7.0.55' + $package_name = 'tomcat' + } + default : { + fail("Unsupported OS version ${::operatingsystemrelease}") + } + } + } + default : { + fail("Unsupported OS ${::operatingsystem}") + } + } + $tomcat_native_package_name = 'libtcnative-1-0' + $log4j_package_name = 'log4j' + } 'Debian' : { case $::operatingsystem { 'Debian' : { @@ -138,7 +194,7 @@ # $package_name = 'tomcat6' } default : { - fail("Unsupported OS version ${::operatingsystemmajrelease}") + fail("Unsupported OS version ${::operatingsystemrelease}") } } } @@ -148,6 +204,7 @@ } $tomcat_native_package_name = 'libtcnative-1' $log4j_package_name = 'liblog4j1.2-java' + $systemd = false } default : { fail("Unsupported OS family ${::osfamily}") diff --git a/manifests/service.pp b/manifests/service.pp index 9de7c86..1bbc443 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -8,6 +8,11 @@ fail('You must include the tomcat base class before using any tomcat sub class') } + if $::operatingsystem == 'OpenSuSE' { + Service { # not explicit on OpenSuSE + provider => systemd } + } + case $::tomcat::installation_support { 'package' : { contain ::tomcat::service::package } default : { contain ::tomcat::service::archive } diff --git a/manifests/service/archive.pp b/manifests/service/archive.pp index feeb3c1..ab547ec 100644 --- a/manifests/service/archive.pp +++ b/manifests/service/archive.pp @@ -9,20 +9,30 @@ } # systemd is prefered if supported - if $::operatingsystem == 'Fedora' or ($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora' and $::operatingsystemmajrelease >= 7) { - file { "${::tomcat::service_name_real} service unit": - path => "/usr/lib/systemd/system/${::tomcat::service_name_real}.service", - owner => 'root', - group => 'root', - content => template("${module_name}/instance/systemd_unit.erb") + if $::tomcat::params::systemd { + if $::operatingsystem == 'OpenSuSE' { + file { "${::tomcat::service_name_real} service unit": + path => "/usr/lib/systemd/system/${::tomcat::service_name_real}.service", + owner => 'root', + group => 'root', + content => template("${module_name}/instance/systemd_unit_suse.erb") + } + } else { # RHEL 7+ or Fedora + file { "${::tomcat::service_name_real} service unit": + path => "/usr/lib/systemd/system/${::tomcat::service_name_real}.service", + owner => 'root', + group => 'root', + content => template("${module_name}/instance/systemd_unit_rhel.erb") + } } service { $::tomcat::service_name_real: - ensure => $::tomcat::service_ensure, - enable => $::tomcat::service_enable, - require => File["${::tomcat::service_name_real} service unit"] + ensure => $::tomcat::service_ensure, + enable => $::tomcat::service_enable, + require => File["${::tomcat::service_name_real} service unit"]; } - } else { # temporary solution until a proper init script is included + # temporary solution until a proper init script is included + } else { $catalina_script = "${::tomcat::catalina_home_real}/bin/catalina.sh" $start_command = "export CATALINA_BASE=${::tomcat::catalina_base_real}; /bin/su ${::tomcat::tomcat_user_real} -s /bin/bash -c '${catalina_script} start'" $stop_command = "export CATALINA_BASE=${::tomcat::catalina_base_real}; /bin/su ${::tomcat::tomcat_user_real} -s /bin/bash -c '${catalina_script} stop'" @@ -31,7 +41,7 @@ service { $::tomcat::service_name_real: ensure => $::tomcat::service_ensure, enable => $::tomcat::service_enable, - provider => 'base', + provider => base, start => $start_command, stop => $stop_command, status => $status_command diff --git a/metadata.json b/metadata.json index d460e96..cc63263 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "aco-tomcat", "summary": "Puppet module for Tomcat", "author": "Antoine Cotten", - "version": "0.4.1", + "version": "0.5.0", "license": "Apache-2.0", "project_page": "https://github.com/tOnI0/aco-tomcat", "source": "git://github.com/tOnI0/aco-tomcat.git", @@ -73,6 +73,37 @@ "21" ] }, + { + "operatingsystem": "SuSE", + "operatingsystemrelease": [ + "11.2", + "11.3", + "12.0" + ] + }, + { + "operatingsystem": "OpenSuSE", + "operatingsystemrelease": [ + "12.3", + "13" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11.2", + "11.3", + "12.0" + ] + }, + { + "operatingsystem": "SLED", + "operatingsystemrelease": [ + "11.2", + "11.3", + "12" + ] + }, { "operatingsystem": "Debian", "operatingsystemrelease": [ diff --git a/templates/instance/systemd_unit.erb b/templates/instance/systemd_unit_rhel.erb similarity index 100% rename from templates/instance/systemd_unit.erb rename to templates/instance/systemd_unit_rhel.erb diff --git a/templates/instance/systemd_unit_suse.erb b/templates/instance/systemd_unit_suse.erb new file mode 100644 index 0000000..d551fff --- /dev/null +++ b/templates/instance/systemd_unit_suse.erb @@ -0,0 +1,18 @@ +[Unit] +Description=Apache Tomcat Web Application Container +After=network.target + +[Service] +Type=simple +EnvironmentFile=-<%= @config_path_real %> +User=<%= scope['::tomcat::tomcat_user_real'] %> +Group=<%= scope['::tomcat::tomcat_group_real'] %> +ExecStart=<%= @service_start_real %> +ExecStop=<%= @service_stop_real %> +StandardOutput=syslog +SyslogIdentifier=%n +SyslogFacility=daemon +SuccessExitStatus=143 + +[Install] +WantedBy=multi-user.target \ No newline at end of file