diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6901db4..8f9b5f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+###0.4.0
+
+* Support installation from archive
+* Use `nanliu/staging` instead of `nanliu/archive` to download and extract files
+* Improved systemd support
+* `create_default_admin` defaults to `false`
+* Numerous improvements in code and documentation
+
###0.3.2
New parameter `manage_firewall`
diff --git a/README.md b/README.md
index 6487287..bdbf7f3 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,7 @@ Use a non-default JVM and run it with custom options
```puppet
class { '::tomcat':
java_home => '/usr/java/jre1.7.0_65',
- java_opts => '-server -Xmx2048m -Xms256m -XX:+UseConcMarkSweepGC'
+ java_opts => ['-server', '-Xmx2048m', '-Xms256m', '-XX:+UseConcMarkSweepGC']
}
```
@@ -88,7 +88,7 @@ class { '::tomcat':
jmx_listener => true,
jmx_registry_port => '8050',
jmx_server_port => '8051',
- catalina_opts => '-Dcom.sun.management.jmxremote'
+ catalina_opts => ['-Dcom.sun.management.jmxremote', '-Dcom.sun.management.jmxremote.ssl=false', '-Dcom.sun.management.jmxremote.authenticate=false']
}
```
@@ -132,7 +132,7 @@ tomcat::instance { 'instance1':
http_port => 8080,
ajp_connector => false,
java_home => '/usr/java/jre1.7.0_65',
- java_opts => '-server -Xmx2048m -Xms256m -XX:+UseConcMarkSweepGC',
+ java_opts => ['-server', '-Xms256m', '-Xmx2048m', '-XX:+UseConcMarkSweepGC'],
}
tomcat::instance { 'instance2':
control_port => 8006,
@@ -160,10 +160,12 @@ Primary class and entry point of the module
#####`version`
Tomcat full version number. The valid format is 'x.y.z'. Default depends on the distribution.
-*Note:* if you define it manually please make **sure** this version if available in your system's repositories, since many parameters depend on this version number
+*Note:* if you install tomcat from package and define this value manually, please make **sure** this version of tomcat if available in your system's repositories, since several sub-parameters depend on it
A list of available versions in each supported distribution is present withing the `params` class.
+#####`archive_source`
+Source of the tomcat server archive, if installed from archive. Defaults to `http://archive.apache.org/dist/tomcat/tomcat-${maj_version}/v${version}/bin/apache-tomcat-${version}.tar.gz`
#####`package_name`
-Tomcat package name. Default depends on the distribution.
+Tomcat package name. Ignored if installed from archive. Default depends on the distribution.
#####`tomcat_native`
Whether to install the Tomcat Native library. Boolean value. Defaults to `false`.
#####`tomcat_native_package_name`
@@ -181,24 +183,30 @@ Create a tomcat instance
**Parameters within `tomcat::instance`:**
-#####`root_path`
-Absolute path to the root of all tomcat instances. Defaults to `/opt/tomcat_instances`.
-*Note:* the instance will be installed in `${root_path}/${title}` and $CATALINA_BASE will be set to that folder.
-
-See also [Common parameters](#common-parameters)
+No instance-specific parameters. See [Common parameters](#common-parameters)
####Common parameters
-Common parameters to `tomcat` and `tomcat::instance`
+Parameters common to both `tomcat` and `tomcat::instance`
**Packages and service**
+#####`root_path`
+Absolute path to the root of all tomcat instances. This parameter is ignored in the global context, unless tomcat was installed from archive. Defaults to `/opt` (global) / `/opt/tomcat_instances` (instance).
+*Notes:*
+* main instance will be installed in `${root_path}/tomcat-${version}` (if installed from archive) and both $CATALINA_HOME and $CATALINA_BASE will be set to that folder
+* other instances will be installed in `${root_path}/${title}` (in all cases) and $CATALINA_BASE will be set to that folder
+
#####`service_name`
Tomcat service name. Defaults to `package_name` (global) / `${package_name}_${title}` (instance).
#####`service_ensure`
Whether the service should be running. Valid values are `stopped` and `running`. Defaults to `running`.
#####`service_enable`
Whether to enable the tomcat service. Boolean value. Defaults to `true`.
+#####`service_start`
+Optional override command for starting the service. Default depends on the platform.
+#####`service_stop`
+Optional override command for stopping the service. Default depends on the platform.
#####`enable_extras`
Whether to install tomcat extra libraries. Boolean value. Defaults to `false`.
*Warning:* enabled globally if defined within the global context
@@ -208,11 +216,11 @@ Whether to automatically manage firewall rules. Boolean value. Defaults to `fals
**Security and administration**
#####`admin_webapps`
-Whether to install admin webapps (manager/host-manager). Boolean value. Defaults to `true`.
+Whether to enable admin webapps (manager/host-manager). This will also install the required packages if tomcat was installed from package. This parameter is ignored if tomcat was installed from archive, since tomcat archives always contain these apps. Boolean value. Defaults to `true`.
#####`admin_webapps_package_name`
Admin webapps package name. Default depends on the distribution.
#####`create_default_admin`
-Whether to create default admin user (roles: 'manager-gui', 'manager-script', 'admin-gui' and 'admin-script'). Boolean value. Defaults to `true`.
+Whether to create default admin user (roles: 'manager-gui', 'manager-script', 'admin-gui' and 'admin-script'). Boolean value. Defaults to `false`.
#####`admin_user`
Admin user name. Defaults to `tomcatadmin`.
#####`admin_password`
@@ -328,5 +336,7 @@ User roles (array of strings)
##To Do
* Support SuSE Linux
+* Proper startup script for distributions which do not have systemd
+* Parameters validation
Features request and contributions are always welcome!
diff --git a/manifests/config.pp b/manifests/config.pp
index 173f827..ea988cf 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -12,6 +12,9 @@
file { 'tomcat server configuration':
path => "${::tomcat::catalina_base_real}/conf/server.xml",
content => template("${module_name}/common/server.xml.erb"),
+ owner => $::tomcat::tomcat_user_real,
+ group => $::tomcat::tomcat_group_real,
+ mode => '0600',
notify => Service[$::tomcat::service_name_real]
}
@@ -24,6 +27,9 @@
'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]
}
@@ -39,7 +45,7 @@
path => "${::tomcat::catalina_base_real}/conf/tomcat-users.xml",
owner => $::tomcat::tomcat_user_real,
group => $::tomcat::tomcat_group_real,
- mode => '0640',
+ mode => '0600',
notify => Service[$::tomcat::service_name_real]
}
diff --git a/manifests/extras.pp b/manifests/extras.pp
index f6cd8a2..ba24f55 100644
--- a/manifests/extras.pp
+++ b/manifests/extras.pp
@@ -6,38 +6,36 @@
fail('You must include the tomcat base class before using any tomcat sub class')
}
- Archive {
- cleanup => false,
+ Staging::File {
require => File['global extras directory'],
notify => Service[$::tomcat::service_name_real]
}
- archive {
+ staging::file {
'catalina-jmx-remote.jar':
- path => "${::tomcat::catalina_home_real}/lib/extras/catalina-jmx-remote-${::tomcat::version}.jar",
+ target => "${::tomcat::catalina_home_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"
;
'catalina-ws.jar':
- path => "${::tomcat::catalina_home_real}/lib/extras/catalina-ws-${::tomcat::version}.jar",
+ target => "${::tomcat::catalina_home_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"
;
'tomcat-juli-adapters.jar':
- path => "${::tomcat::catalina_home_real}/lib/extras/tomcat-juli-adapters-${::tomcat::version}.jar",
+ target => "${::tomcat::catalina_home_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"
;
'tomcat-juli-extras.jar':
- path => "${::tomcat::catalina_home_real}/lib/extras/tomcat-juli-extras-${::tomcat::version}.jar",
+ target => "${::tomcat::catalina_home_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 {
'global extras directory':
- ensure => directory,
- path => "${::tomcat::catalina_home_real}/lib/extras",
- seltype => 'usr_t';
+ ensure => directory,
+ path => "${::tomcat::catalina_home_real}/lib/extras";
'tomcat-juli.jar':
ensure => link,
@@ -46,27 +44,23 @@
backup => true;
'catalina-jmx-remote.jar':
- ensure => link,
- path => "${::tomcat::catalina_home_real}/lib/catalina-jmx-remote.jar",
- target => "extras/catalina-jmx-remote-${::tomcat::version}.jar",
- seltype => 'usr_t';
+ ensure => link,
+ path => "${::tomcat::catalina_home_real}/lib/catalina-jmx-remote.jar",
+ target => "extras/catalina-jmx-remote-${::tomcat::version}.jar";
'catalina-ws.jar':
- ensure => link,
- path => "${::tomcat::catalina_home_real}/lib/catalina-ws.jar",
- target => "extras/catalina-ws-${::tomcat::version}.jar",
- seltype => 'usr_t';
+ ensure => link,
+ path => "${::tomcat::catalina_home_real}/lib/catalina-ws.jar",
+ target => "extras/catalina-ws-${::tomcat::version}.jar";
'tomcat-juli-adapters.jar':
- ensure => link,
- path => "${::tomcat::catalina_home_real}/lib/tomcat-juli-adapters.jar",
- target => "extras/tomcat-juli-adapters-${::tomcat::version}.jar",
- seltype => 'usr_t';
+ ensure => link,
+ path => "${::tomcat::catalina_home_real}/lib/tomcat-juli-adapters.jar",
+ target => "extras/tomcat-juli-adapters-${::tomcat::version}.jar";
'tomcat-juli-extras.jar':
- ensure => link,
- path => "${::tomcat::catalina_home_real}/lib/tomcat-juli-extras.jar",
- target => "extras/tomcat-juli-extras-${::tomcat::version}.jar",
- seltype => 'usr_t'
+ ensure => link,
+ path => "${::tomcat::catalina_home_real}/lib/tomcat-juli-extras.jar",
+ target => "extras/tomcat-juli-extras-${::tomcat::version}.jar"
}
}
\ No newline at end of file
diff --git a/manifests/init.pp b/manifests/init.pp
index b427a24..8b76d56 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -4,6 +4,12 @@
#
# === Parameters:
#
+# [*installation_support*]
+# what type of source to install from (valid: 'package'|'archive')
+# [*archive_source*]
+# where to download archive from (*only* if installed from archive)
+# [*root_path*]
+# root installation path (*only* if installed from archive)
# [*version*]
# tomcat full version number (valid format: x.y.z)
# [*package_name*]
@@ -14,6 +20,10 @@
# whether the service should be running (valid: 'stopped'|'running')
# [*service_enable*]
# enable service (boolean)
+# [*service_start*]
+# override service startup command
+# [*service_stop*]
+# override service shutdown command
# [*tomcat_native*]
# install tomcat native library (boolean)
# [*tomcat_native_package_name*]
@@ -27,7 +37,7 @@
# [*manage_firewall*]
# manage firewall rules (boolean)
# [*admin_webapps*]
-# install admin webapps (boolean)
+# install admin webapps (boolean - *only* if installed from package)
# [*admin_webapps_package_name*]
# admin webapps package name
# [*create_default_admin*]
@@ -64,11 +74,16 @@
#----------------------------------------------------------------------------------
# packages and service
#----------------------------------------------------------------------------------
+ $installation_support = 'package',
+ $archive_source = undef,
+ $root_path = '/opt',
$version = $::tomcat::params::version,
$package_name = $::tomcat::params::package_name,
$service_name = undef,
$service_ensure = 'running',
$service_enable = true,
+ $service_start = undef,
+ $service_stop = undef,
$tomcat_native = false,
$tomcat_native_package_name = $::tomcat::params::tomcat_native_package_name,
$log4j = false,
@@ -80,7 +95,7 @@
#----------------------------------------------------------------------------------
$admin_webapps = true,
$admin_webapps_package_name = undef,
- $create_default_admin = true,
+ $create_default_admin = false,
$admin_user = 'tomcatadmin',
$admin_password = 'password',
#----------------------------------------------------------------------------------
@@ -152,12 +167,24 @@
$shutdown_wait = 30,
$shutdown_verbose = false,
$custom_fragment = undef) inherits tomcat::params {
+ # get major version
+ $array_version = split($version, '[.]')
+ $maj_version = $array_version[0]
+
# autogenerated defaults
if $service_name == undef {
- $service_name_real = $package_name
- } else {
+ $service_name_real = $installation_support ? {
+ 'package' => $package_name,
+ default => "tomcat${maj_version}"
+ } } else {
$service_name_real = $service_name
}
+
+ if $archive_source == undef {
+ $archive_source_real = "http://archive.apache.org/dist/tomcat/tomcat-${maj_version}/v${version}/bin/apache-tomcat-${version}.tar.gz"
+ } else {
+ $archive_source_real = $archive_source
+ }
if $admin_webapps_package_name == undef {
$admin_webapps_package_name_real = $::osfamily ? {
@@ -166,27 +193,27 @@
} } else {
$admin_webapps_package_name_real = $admin_webapps_package_name
}
-
- if $config_path == undef {
- $config_path_real = $::osfamily ? {
- 'RedHat' => "/etc/sysconfig/${service_name_real}",
- default => "/etc/default/${service_name_real}"
- }
- } else {
- $config_path_real = $config_path
- }
if $catalina_home == undef {
- $catalina_home_real = "/usr/share/${service_name_real}"
- } else {
+ $catalina_home_real = $installation_support ? {
+ 'package' => "/usr/share/${service_name_real}",
+ default => "${root_path}/tomcat-${version}"
+ } } else {
$catalina_home_real = $catalina_home
}
if $catalina_base == undef {
- $catalina_base_real = $::osfamily ? {
- 'RedHat' => $catalina_home_real,
- default => "/var/lib/${service_name_real}"
- } } else {
+ case $installation_support {
+ 'package' : {
+ $catalina_base_real = $::osfamily ? {
+ 'RedHat' => $catalina_home_real,
+ default => "/var/lib/${service_name_real}"
+ } }
+ default : {
+ $catalina_base_real = $catalina_home_real
+ }
+ }
+ } else {
$catalina_base_real = $catalina_base
}
@@ -197,19 +224,58 @@
}
if $catalina_tmpdir == undef {
- $catalina_tmpdir_real = $::osfamily ? {
- 'Debian' => '$JVM_TMP',
- default => "${catalina_base_real}/temp"
- } } else {
+ case $installation_support {
+ 'package' : {
+ $catalina_tmpdir_real = $::osfamily ? {
+ 'Debian' => '$JVM_TMP',
+ default => "${catalina_base_real}/temp"
+ } }
+ default : {
+ $catalina_tmpdir_real = "${catalina_base_real}/temp"
+ }
+ }
+ } else {
$catalina_tmpdir_real = $catalina_tmpdir
}
if $catalina_pid == undef {
- $catalina_pid_real = "/var/run/${service_name_real}.pid"
+ case $::tomcat::installation_support {
+ 'package' : { $catalina_pid_real = "/var/run/${service_name_real}.pid" }
+ default : { $catalina_pid_real = "${catalina_tmpdir_real}/${service_name_real}.pid" }
+ }
} else {
$catalina_pid_real = $catalina_pid
}
+ if $config_path == undef {
+ case $installation_support {
+ 'package' : {
+ $config_path_real = $::osfamily ? {
+ 'RedHat' => "/etc/sysconfig/${service_name_real}",
+ default => "/etc/default/${service_name_real}"
+ } }
+ default : {
+ $config_path_real = "${catalina_base_real}/bin/setenv.sh"
+ }
+ }
+ } else {
+ $config_path_real = $config_path
+ }
+
+ if $service_start == undef {
+ case $installation_support {
+ 'package' : { $service_start_real = '/usr/sbin/tomcat-sysd stop' }
+ default : { $service_start_real = "${catalina_home_real}/bin/catalina.sh start" }
+ }
+ }
+
+ if $service_stop == undef {
+ case $installation_support {
+ 'package' : { $service_stop_real = '/usr/sbin/tomcat-sysd stop' }
+ default : { $service_stop_real = "${catalina_home_real}/bin/catalina.sh stop" }
+ }
+ }
+
$java_opts_real = join($java_opts, ' ')
$catalina_opts_real = join($catalina_opts, ' ')
@@ -235,21 +301,12 @@
$security_manager_real = $security_manager
}
- # get major version
- $array_version = split($version, '[.]')
- $maj_version = $array_version[0]
-
# should we force download extras libs?
if $log4j_enable or $jmx_listener {
$enable_extras_real = true
} else {
$enable_extras_real = $enable_extras
}
-
- # module dependency
- if !defined(Class['archive']) {
- include ::archive
- }
# start the real action
include tomcat::install
diff --git a/manifests/install.pp b/manifests/install.pp
index 2201729..2fc65f5 100644
--- a/manifests/install.pp
+++ b/manifests/install.pp
@@ -1,15 +1,16 @@
# == Class: tomcat::install
#
+# This class is a wrapper to install tomcat either from packages or archive
+#
class tomcat::install {
# The base class must be included first
if !defined(Class['tomcat']) {
fail('You must include the tomcat base class before using any tomcat sub class')
}
- # main packages
- package { 'tomcat server':
- ensure => present,
- name => $::tomcat::package_name
+ case $::tomcat::installation_support {
+ 'package' : { contain ::tomcat::install::package }
+ default : { contain ::tomcat::install::archive }
}
# tomcat native library
@@ -21,7 +22,7 @@
ensure => $ensure_native_package,
name => $::tomcat::tomcat_native_package_name
}
-
+
# log4j library
$ensure_log4j_package = $::tomcat::log4j ? {
true => 'present',
@@ -33,21 +34,14 @@
}
# install admin webapps
- $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
- }
-
- # fix broken status check in some tomcat init scripts
- 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})\"",
- match => 'pid=.*pgrep'
+ 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
}
}
}
\ No newline at end of file
diff --git a/manifests/install/archive.pp b/manifests/install/archive.pp
new file mode 100644
index 0000000..947cef7
--- /dev/null
+++ b/manifests/install/archive.pp
@@ -0,0 +1,46 @@
+# == Class: tomcat::install::archive
+#
+# This class installs tomcat from an archive
+#
+class tomcat::install::archive {
+ # The base class must be included first
+ if !defined(Class['tomcat']) {
+ fail('You must include the tomcat base class before using any tomcat sub class')
+ }
+
+ # create user if not present
+ group { $::tomcat::tomcat_group_real: ensure => present } ->
+ user { $::tomcat::tomcat_user_real:
+ ensure => present,
+ gid => $::tomcat::tomcat_group_real,
+ home => $::tomcat::catalina_home_real,
+ system => true
+ }
+
+ File {
+ owner => $::tomcat::tomcat_user_real,
+ group => $::tomcat::tomcat_group_real
+ }
+
+ # install from archive
+ file { $::tomcat::catalina_home_real: ensure => directory } ->
+ staging::file { "apache-tomcat-${::tomcat::version}.tar.gz": source => $::tomcat::archive_source_real } ->
+ staging::extract { "apache-tomcat-${::tomcat::version}.tar.gz":
+ target => $::tomcat::catalina_home_real,
+ creates => "${::tomcat::catalina_home_real}/bin",
+ user => $::tomcat::tomcat_user_real,
+ group => $::tomcat::tomcat_group_real,
+ strip => 1
+ } ->
+ file { 'tomcat logs symlink':
+ ensure => link,
+ path => "${::tomcat::catalina_base_real}/logs",
+ target => "/var/log/${::tomcat::service_name_real}",
+ force => true
+ }
+
+ file { 'tomcat logs directory':
+ ensure => directory,
+ path => "/var/log/${::tomcat::service_name_real}"
+ }
+}
\ No newline at end of file
diff --git a/manifests/install/package.pp b/manifests/install/package.pp
new file mode 100644
index 0000000..aedcc8f
--- /dev/null
+++ b/manifests/install/package.pp
@@ -0,0 +1,26 @@
+# == Class: tomcat::install::package
+#
+# This class installs tomcat from installation packages
+#
+class tomcat::install::package {
+ # The base class must be included first
+ if !defined(Class['tomcat']) {
+ fail('You must include the tomcat base class before using any tomcat sub class')
+ }
+
+ # install packages
+ package { 'tomcat server':
+ ensure => present,
+ name => $::tomcat::package_name
+ }
+
+ # fix broken status check in some tomcat init scripts
+ if $::osfamily == 'RedHat' and $::operatingsystemmajrelease < 7 and $::tomcat::installation_support == 'package' {
+ 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})\"",
+ match => 'pid=.*pgrep',
+ require => Package['tomcat server']
+ }
+ }
+}
\ No newline at end of file
diff --git a/manifests/instance.pp b/manifests/instance.pp
index f34759a..9a1780c 100644
--- a/manifests/instance.pp
+++ b/manifests/instance.pp
@@ -4,7 +4,32 @@
#
# === Parameters:
#
-# see README file for a description of all parameters
+# [*root_path*]
+# common root installation path for all instances
+# [*service_name*]
+# tomcat service name
+# [*service_ensure*]
+# whether the service should be running (valid: 'stopped'|'running')
+# [*service_enable*]
+# enable service (boolean)
+# [*service_start*]
+# override service startup command
+# [*service_stop*]
+# override service shutdown command
+# [*enable_extras*]
+# install extra libraries (boolean)
+# [*manage_firewall*]
+# manage firewall rules (boolean)
+# [*admin_webapps*]
+# enable admin webapps (boolean)
+# [*create_default_admin*]
+# create default admin user (boolean)
+# [*admin_user*]
+# admin user name
+# [*admin_password*]
+# admin user password
+#
+# see README file for a description of all parameters related to server configuration
#
# === Actions:
#
@@ -34,7 +59,7 @@
# security and administration
#----------------------------------------------------------------------------------
$admin_webapps = true,
- $create_default_admin = true,
+ $create_default_admin = false,
$admin_user = 'tomcatadmin',
$admin_password = 'password',
#----------------------------------------------------------------------------------
@@ -117,17 +142,11 @@
# -----------------------#
if $service_name == undef {
- $service_name_real = "${::tomcat::service_name_real}_${name}"
- } else {
- $service_name_real = $service_name
- }
-
- if $config_path == undef {
- $config_path_real = $::osfamily ? {
- 'RedHat' => "/etc/sysconfig/${service_name_real}",
- default => "/etc/default/${service_name_real}"
+ $service_name_real = $::tomcat::installation_support ? {
+ 'package' => "${::tomcat::package_name}_${name}",
+ default => "${::tomcat::service_name_real}_${name}"
} } else {
- $config_path_real = $config_path
+ $service_name_real = $service_name
}
if $catalina_home == undef {
@@ -149,19 +168,58 @@
}
if $catalina_tmpdir == undef {
- $catalina_tmpdir_real = $::osfamily ? {
- 'Debian' => '$JVM_TMP',
- default => "${catalina_base_real}/temp"
- } } else {
+ case $::tomcat::installation_support {
+ 'package' : {
+ $catalina_tmpdir_real = $::osfamily ? {
+ 'Debian' => '$JVM_TMP',
+ default => "${catalina_base_real}/temp"
+ } }
+ default : {
+ $catalina_tmpdir_real = "${catalina_base_real}/temp"
+ }
+ }
+ } else {
$catalina_tmpdir_real = $catalina_tmpdir
}
if $catalina_pid == undef {
- $catalina_pid_real = "/var/run/${service_name_real}.pid"
+ case $::tomcat::installation_support {
+ 'package' : { $catalina_pid_real = "/var/run/${service_name_real}.pid" }
+ default : { $catalina_pid_real = "${catalina_tmpdir_real}/${service_name_real}.pid" }
+ }
} else {
$catalina_pid_real = $catalina_pid
}
+ if $config_path == undef {
+ case $::tomcat::installation_support {
+ 'package' : {
+ $config_path_real = $::osfamily ? {
+ 'RedHat' => "/etc/sysconfig/${service_name_real}",
+ default => "/etc/default/${service_name_real}"
+ } }
+ default : {
+ $config_path_real = "${catalina_base_real}/bin/setenv.sh"
+ }
+ }
+ } else {
+ $config_path_real = $config_path
+ }
+
+ if $service_start == undef {
+ case $::tomcat::installation_support {
+ 'package' : { $service_start_real = '/usr/sbin/tomcat-sysd stop' }
+ default : { $service_start_real = "${catalina_home_real}/bin/catalina.sh start" }
+ }
+ }
+
+ if $service_stop == undef {
+ case $::tomcat::installation_support {
+ 'package' : { $service_stop_real = '/usr/sbin/tomcat-sysd stop' }
+ default : { $service_stop_real = "${catalina_home_real}/bin/catalina.sh stop" }
+ }
+ }
+
$java_opts_real = join($java_opts, ' ')
$catalina_opts_real = join($catalina_opts, ' ')
@@ -184,38 +242,73 @@
# service #
# --------#
- if $::osfamily == 'Debian' and $tomcat::maj_version > 6 {
- file { "${service_name_real} service unit":
- path => "/etc/init.d/${service_name_real}",
- owner => 'root',
- group => 'root',
- mode => '0755',
- content => template("${module_name}/instance/${::tomcat::service_name_real}_init_deb.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")
+ case $::tomcat::installation_support {
+ 'package' : {
+ # manage startup script/unit
+ if $::osfamily == 'Debian' and $tomcat::maj_version > 6 {
+ file { "${service_name_real} service unit":
+ path => "/etc/init.d/${service_name_real}",
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ content => template("${module_name}/instance/tomcat${::tomcat::maj_version}_init_deb.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")
+ }
+ } else {
+ file { "${service_name_real} service unit":
+ ensure => link,
+ path => "/etc/init.d/${service_name_real}",
+ owner => 'root',
+ group => 'root',
+ target => $::tomcat::service_name_real
+ }
+ }
+
+ service { $service_name_real:
+ ensure => $service_ensure,
+ enable => $service_enable,
+ require => File["${service_name_real} service unit"]
+ }
}
- } else {
- file { "${service_name_real} service unit":
- ensure => link,
- path => "/etc/init.d/${service_name_real}",
- owner => 'root',
- group => 'root',
- target => $::tomcat::service_name_real,
- seltype => 'etc_t'
+ 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")
+ }
+
+ service { $service_name_real:
+ ensure => $service_ensure,
+ enable => $service_enable,
+ require => File["${service_name_real} service unit"];
+ }
+ } else { # temporary solution until a proper init script is included
+ $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'"
+ $status_command = "/usr/bin/pgrep -d , -u ${::tomcat::tomcat_user_real} -G ${::tomcat::tomcat_group_real} -f Dcatalina.base=${catalina_base_real}"
+
+ # generate tomcat service
+ service { $service_name_real:
+ ensure => $service_ensure,
+ enable => $service_enable,
+ provider => 'base',
+ start => $start_command,
+ stop => $stop_command,
+ status => $status_command
+ }
+ }
}
}
- service { $service_name_real:
- ensure => $service_ensure,
- enable => $service_enable,
- require => File["${service_name_real} service unit"];
- }
-
# ---------------------#
# instance directories #
# ---------------------#
@@ -273,7 +366,7 @@
path => "${catalina_base_real}/temp"
}
- if $::osfamily == 'Debian' {
+ if $::osfamily == 'Debian' and $::tomcat::installation_support == 'package' {
file { "instance ${name} conf/policy.d directory":
ensure => directory,
path => "${catalina_base_real}/conf/policy.d",
@@ -295,6 +388,9 @@
file { "instance ${name} server configuration":
path => "${catalina_base_real}/conf/server.xml",
content => template("${module_name}/common/server.xml.erb"),
+ owner => $::tomcat::tomcat_user_real,
+ group => $::tomcat::tomcat_group_real,
+ mode => '0600',
notify => Service[$service_name_real]
}
@@ -306,6 +402,9 @@
file { "instance ${name} environment variables":
path => $config_path_real,
content => template("${module_name}/common/setenv.erb"),
+ owner => $::tomcat::tomcat_user_real,
+ group => $::tomcat::tomcat_group_real,
+ mode => '0644',
notify => Service[$service_name_real]
}
@@ -325,7 +424,7 @@
path => "${catalina_base_real}/conf/tomcat-users.xml",
owner => $::tomcat::tomcat_user_real,
group => $::tomcat::tomcat_group_real,
- mode => '0640',
+ mode => '0600',
notify => Service[$service_name_real]
}
@@ -454,30 +553,29 @@
# -------#
if $enable_extras_real and !$::tomcat::enable_extras_real { # no need to duplicate libraries if enabled globally
- Archive {
- cleanup => false,
+ Staging::File {
require => File["instance ${name} extras directory"],
notify => Service[$service_name_real]
}
- archive {
+ staging::file {
"instance ${name} catalina-jmx-remote.jar":
- path => "${catalina_base_real}/lib/extras/catalina-jmx-remote-${::tomcat::version}.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":
- path => "${catalina_base_real}/lib/extras/catalina-ws-${::tomcat::version}.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":
- path => "${catalina_base_real}/lib/extras/tomcat-juli-adapters-${::tomcat::version}.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":
- path => "${catalina_base_real}/lib/extras/tomcat-juli-extras-${::tomcat::version}.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"
}
diff --git a/manifests/log4j.pp b/manifests/log4j.pp
index 14e7fee..f41dca0 100644
--- a/manifests/log4j.pp
+++ b/manifests/log4j.pp
@@ -18,48 +18,44 @@
}
file { 'global log4j library':
- ensure => link,
- owner => 'root',
- group => 'root',
- path => "${::tomcat::catalina_home_real}/lib/log4j.jar",
- target => $log4j_path,
- seltype => 'usr_t',
- notify => Service[$::tomcat::service_name_real]
+ ensure => link,
+ owner => 'root',
+ group => 'root',
+ path => "${::tomcat::catalina_home_real}/lib/log4j.jar",
+ target => $log4j_path,
+ notify => Service[$::tomcat::service_name_real]
}
if $::tomcat::log4j_conf_type == 'xml' {
file {
'global log4j xml configuration':
- ensure => present,
- owner => 'root',
- group => 'root',
- path => "${::tomcat::catalina_home_real}/lib/log4j.xml",
- source => $::tomcat::log4j_conf_source,
- seltype => 'lib_t',
- notify => Service[$::tomcat::service_name_real];
+ ensure => present,
+ owner => 'root',
+ group => 'root',
+ path => "${::tomcat::catalina_home_real}/lib/log4j.xml",
+ source => $::tomcat::log4j_conf_source,
+ notify => Service[$::tomcat::service_name_real];
'global log4j ini configuration':
ensure => absent,
path => "${::tomcat::catalina_home_real}/lib/log4j.properties";
'global log4j dtd file':
- ensure => present,
- owner => 'root',
- group => 'root',
- path => "${::tomcat::catalina_home_real}/lib/log4j.dtd",
- source => "puppet:///modules/${module_name}/log4j/log4j.dtd",
- seltype => 'usr_t'
+ ensure => present,
+ owner => 'root',
+ group => 'root',
+ path => "${::tomcat::catalina_home_real}/lib/log4j.dtd",
+ source => "puppet:///modules/${module_name}/log4j/log4j.dtd"
}
} else {
file {
'global log4j ini configuration':
- ensure => present,
- owner => 'root',
- group => 'root',
- path => "${::tomcat::catalina_home_real}/lib/log4j.properties",
- source => $::tomcat::log4j_conf_source,
- seltype => 'lib_t',
- notify => Service[$::tomcat::service_name_real];
+ ensure => present,
+ owner => 'root',
+ group => 'root',
+ path => "${::tomcat::catalina_home_real}/lib/log4j.properties",
+ source => $::tomcat::log4j_conf_source,
+ notify => Service[$::tomcat::service_name_real];
'global log4j xml configuration':
ensure => absent,
diff --git a/manifests/service.pp b/manifests/service.pp
index c2be853..9de7c86 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -1,13 +1,15 @@
# == Class: tomcat::service
#
+# This class is a wrapper to configure the appropriate tomcat service
+#
class tomcat::service {
# The base class must be included first
if !defined(Class['tomcat']) {
fail('You must include the tomcat base class before using any tomcat sub class')
}
- service { $::tomcat::service_name_real:
- ensure => $::tomcat::service_ensure,
- enable => $::tomcat::service_enable
+ case $::tomcat::installation_support {
+ 'package' : { contain ::tomcat::service::package }
+ default : { contain ::tomcat::service::archive }
}
}
\ No newline at end of file
diff --git a/manifests/service/archive.pp b/manifests/service/archive.pp
new file mode 100644
index 0000000..feeb3c1
--- /dev/null
+++ b/manifests/service/archive.pp
@@ -0,0 +1,40 @@
+# == Class: tomcat::service::archive
+#
+# This class configures the tomcat service when installed from archive
+#
+class tomcat::service::archive {
+ # The base class must be included first
+ if !defined(Class['tomcat']) {
+ fail('You must include the tomcat base class before using any tomcat sub class')
+ }
+
+ # 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")
+ }
+
+ service { $::tomcat::service_name_real:
+ 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
+ $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'"
+ $status_command = "/usr/bin/pgrep -d , -u ${::tomcat::tomcat_user_real} -G ${::tomcat::tomcat_group_real} -f Dcatalina.base=${::tomcat::catalina_base_real}"
+
+ service { $::tomcat::service_name_real:
+ ensure => $::tomcat::service_ensure,
+ enable => $::tomcat::service_enable,
+ provider => 'base',
+ start => $start_command,
+ stop => $stop_command,
+ status => $status_command
+ }
+ }
+}
\ No newline at end of file
diff --git a/manifests/service/package.pp b/manifests/service/package.pp
new file mode 100644
index 0000000..5e43856
--- /dev/null
+++ b/manifests/service/package.pp
@@ -0,0 +1,16 @@
+# == Class: tomcat::service::package
+#
+# This class configures the tomcat service when installed from packages
+#
+class tomcat::service::package {
+ # The base class must be included first
+ if !defined(Class['tomcat']) {
+ fail('You must include the tomcat base class before using any tomcat sub class')
+ }
+
+ # tomcat service
+ service { $::tomcat::service_name_real:
+ ensure => $::tomcat::service_ensure,
+ enable => $::tomcat::service_enable
+ }
+}
\ No newline at end of file
diff --git a/metadata.json b/metadata.json
index 9e7f1d9..f7ca54e 100644
--- a/metadata.json
+++ b/metadata.json
@@ -2,7 +2,7 @@
"name": "aco-tomcat",
"summary": "Puppet module for Tomcat",
"author": "Antoine Cotten",
- "version": "0.3.2",
+ "version": "0.4.0",
"license": "Apache-2.0",
"project_page": "https://github.com/tOnI0/aco-tomcat",
"source": "git://github.com/tOnI0/aco-tomcat.git",
@@ -10,19 +10,19 @@
"dependencies": [
{
"name": "puppetlabs/concat",
- "version_requirement": ">= 1.0.0 <2.0.0"
+ "version_requirement": ">= 1.0.0 < 2.0.0"
},
{
"name": "puppetlabs/stdlib",
- "version_requirement": ">= 1.0.0 <5.0.0"
+ "version_requirement": ">= 1.0.0 < 5.0.0"
},
{
"name": "puppetlabs/firewall",
- "version_requirement": ">= 1.1.3 <2.0.0"
+ "version_requirement": ">= 1.1.3 < 2.0.0"
},
{
- "name": "nanliu/archive",
- "version_requirement": ">= 0.1.7 <1.0.0"
+ "name": "nanliu/staging",
+ "version_requirement": ">= 1.0.0 < 2.0.0"
}
],
"operatingsystem_support": [
diff --git a/templates/common/UserDatabase_entry.erb b/templates/common/UserDatabase_entry.erb
index 8cd1170..5f5fa83 100644
--- a/templates/common/UserDatabase_entry.erb
+++ b/templates/common/UserDatabase_entry.erb
@@ -1 +1 @@
-
+
diff --git a/templates/common/UserDatabase_header.erb b/templates/common/UserDatabase_header.erb
index 4ac7f2c..ebe39de 100644
--- a/templates/common/UserDatabase_header.erb
+++ b/templates/common/UserDatabase_header.erb
@@ -4,37 +4,4 @@
# Managed by Puppet
# ******************
-->
-
-
-
-
diff --git a/templates/instance/systemd_unit.erb b/templates/instance/systemd_unit.erb
index a04abe2..ae68967 100644
--- a/templates/instance/systemd_unit.erb
+++ b/templates/instance/systemd_unit.erb
@@ -4,16 +4,8 @@ After=syslog.target network.target
[Service]
Type=forking
-<% if @service_start -%>
-ExecStart=<%= @service_start %>
-<% else -%>
-ExecStart=/usr/sbin/tomcat-sysd start
-<% end -%>
-<% if @service_stop -%>
-ExecStop=<%= @service_stop %>
-<% else -%>
-ExecStop=/usr/sbin/tomcat-sysd stop
-<% end -%>
+ExecStart=<%= @service_start_real %>
+ExecStop=<%= @service_stop_real %>
SuccessExitStatus=143
User=<%= scope['::tomcat::tomcat_user_real'] %>
Group=<%= scope['::tomcat::tomcat_group_real'] %>