Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Add support for complex Host setup (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerveMARTIN authored and antoineco committed Jul 23, 2018
1 parent 918992e commit 479c149
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 36 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,32 @@ class { 'tomcat':
}
```

or for more complex setup
```puppet
class { 'tomcat':
hosts => [
{
name => 'www.example.org',
deployonstartup => false,
unpackwars => true,
createDirs => true,
contexts => [{ path => '', docBase => '/home/app', crossContext => true }],
valves => [{ className => 'org.apache.catalina.valves.AccessLogValve', directory => 'logs', prefix => 'app_access_log', suffix => '.txt', pattern => '%h %l %u %t "%r" %s %b'}]
},
{
name => 'cas.example.org',
deployonstartup => false,
unpackwars => true,
createDirs => true,
contexts => [{ path => '', docBase => '/home/cas', crossContext => true }],
valves => [{ className => 'org.apache.catalina.valves.AccessLogValve', directory => 'logs', prefix => 'cas_access_log', suffix => '.txt', pattern => '%h %l %u %t "%r" %s %b'}]
}
]
}
```

Enable the remote [JMX listener](http://tomcat.apache.org/tomcat-9.0-doc/config/listeners.html#JMX_Remote_Lifecycle_Listener_-_org.apache.catalina.mbeans.JmxRemoteLifecycleListener) and remote JVM monitoring

```puppet
Expand Down Expand Up @@ -465,9 +491,15 @@ Optional override command for stopping the service. Default depends on the platf
##### `tomcat_user`
Tomcat user. Defaults to [`${service_name}`](#service_name) (Debian) / `tomcat` (all other distributions).

##### `tomcat_user_id`
Tomcat user id. Defaults to undef, will be generated at user creation.

##### `tomcat_group`
Tomcat group. Defaults to [`${tomcat_user}`](#tomcat_user).

##### `tomcat_group_id`
Tomcat group id. Defaults to undef, will be generated at group creation.

##### `file_mode`
File mode for certain configuration xml files. Defaults to '0600'.

Expand Down Expand Up @@ -620,6 +652,10 @@ Name of the default [Host](http://tomcat.apache.org/tomcat-9.0-doc/config/host.h
- `host_unpackwars`: whether to unpack web application archive (WAR) files
- `host_params`: optional hash of additional attributes/values to put in the Host container

##### `hosts`
An array of `Host` entries. Use this if you need more complex setup. You can nest valves and contexts with their parameters.
See [Host](http://tomcat.apache.org/tomcat-9.0-doc/config/host.html) for the list of possible attributes.

##### `contexts`
An array of custom `Context` entries to be added to the `Host` container. Each entry is to be supplied as a hash of attributes/values for the `Context` XML node. See [Context](http://tomcat.apache.org/tomcat-9.0-doc/config/context.html) for the list of possible attributes.

Expand Down
72 changes: 46 additions & 26 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
$engine_params_real = $::tomcat::engine_params_real
$host_name = $::tomcat::host_name
$host_params_real = $::tomcat::host_params_real
$hosts = $::tomcat::hosts
$contexts = $::tomcat::contexts
$use_simpletcpcluster = $::tomcat::use_simpletcpcluster
$cluster_membership_port = $::tomcat::cluster_membership_port
Expand All @@ -68,6 +69,7 @@
$globalnaming_environments = $::tomcat::globalnaming_environments
$globalnaming_resources = $::tomcat::globalnaming_resources
$context_params = $::tomcat::context_params
$context_cookieprocessor = $::tomcat::context_cookieprocessor
$context_loader = $::tomcat::context_loader
$context_manager = $::tomcat::context_manager
$context_realm = $::tomcat::context_realm
Expand Down Expand Up @@ -279,34 +281,51 @@
}
}

# Template uses:
# - $host_name
# - $host_params_real
concat::fragment { 'server.xml host':
order => 90,
content => template("${module_name}/common/server.xml/090_host.erb"),
target => 'tomcat server configuration'
}
if (empty($hosts)) {
# Template uses:
# - $host_name
# - $host_params_real
concat::fragment { 'server.xml host':
order => 90,
content => template("${module_name}/common/server.xml/090_host.erb"),
target => 'tomcat server configuration'
}

# Template uses:
# - $contexts
concat::fragment { 'server.xml contexts':
order => 95,
content => template("${module_name}/common/server.xml/095_contexts.erb"),
target => 'tomcat server configuration'
}
# Template uses:
# - $contexts
concat::fragment { 'server.xml contexts':
order => 95,
content => template("${module_name}/common/server.xml/095_contexts.erb"),
target => 'tomcat server configuration'
}

# Template uses:
# - $singlesignon_valve
# - $accesslog_valve
# - $accesslog_valve_pattern
# - $valves
# - $host_name
# - $maj_version
if $singlesignon_valve or $accesslog_valve or ($valves and $valves != []) {
concat::fragment { 'server.xml valves':
order => 100,
content => template("${module_name}/common/server.xml/100_valves.erb"),
# Template uses:
# - $singlesignon_valve
# - $accesslog_valve
# - $accesslog_valve_pattern
# - $valves
# - $host_name
# - $maj_version
if $singlesignon_valve or $accesslog_valve or ($valves and $valves != []) {
concat::fragment { 'server.xml valves':
order => 100,
content => template("${module_name}/common/server.xml/100_valves.erb"),
target => 'tomcat server configuration'
}
}

# Template uses no variable, just </Host>
concat::fragment { 'server.xml host close':
order => 190,
content => template("${module_name}/common/server.xml/190_host_close.erb"),
target => 'tomcat server configuration'
}
} else {
# Template uses :
# - $hosts
concat::fragment { 'server.xml hosts':
order => 91,
content => template("${module_name}/common/server.xml/091_hosts.erb"),
target => 'tomcat server configuration'
}
}
Expand All @@ -322,6 +341,7 @@
path => "${::tomcat::catalina_base_real}/conf/context.xml",
file_mode => $::tomcat::file_mode,
params => $context_params,
cookieprocessor => $context_cookieprocessor,
loader => $context_loader,
manager => $context_manager,
realm => $context_realm,
Expand Down
23 changes: 19 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
# override service shutdown command
# [*tomcat_user*]
# service user
# [*tomcat_user_id*]
# service user id
# [*tomcat_group*]
# service group
# [*tomcat_group_id*]
# service group id
# [*file_mode*]
# mode for configuration files
# [*tomcat_native*]
Expand Down Expand Up @@ -120,7 +124,9 @@
$service_start = undef,
$service_stop = undef,
$tomcat_user = undef,
$tomcat_user_id = undef,
$tomcat_group = undef,
$tomcat_group_id = undef,
$file_mode = '0600',
$tomcat_native = false,
$tomcat_native_package_name = $::tomcat::params::tomcat_native_package_name,
Expand Down Expand Up @@ -261,6 +267,7 @@
$host_undeployoldversions = undef,
$host_unpackwars = undef,
$host_params = {},
$hosts = {},
#..................................................................................
# host contexts
$contexts = [],
Expand Down Expand Up @@ -559,13 +566,21 @@
$security_manager_real = $security_manager ? {
true => 'yes',
default => 'no'
} } else {
}
} else {
$security_manager_real = $security_manager
}

$engine_defaulthost_real = $engine_defaulthost ? {
undef => $host_name,
default => $engine_defaulthost
if (empty($hosts)) {
$engine_defaulthost_real = $engine_defaulthost ? {
undef => $host_name,
default => $engine_defaulthost
}
} else {
$engine_defaulthost_real = $engine_defaulthost ? {
undef => $hosts[0]['name'],
default => $engine_defaulthost
}
}

$java_opts_real = join($java_opts, ' ')
Expand Down
2 changes: 2 additions & 0 deletions manifests/install/archive.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
if !defined(Group[$::tomcat::tomcat_group_real]) {
group { $::tomcat::tomcat_group_real:
ensure => present,
gid => $::tomcat::tomcat_group_id,
system => true
}
}

if !defined(User[$::tomcat::tomcat_user_real]) {
user { $::tomcat::tomcat_user_real:
ensure => present,
uid => $::tomcat::tomcat_user_id,
gid => $::tomcat::tomcat_group_real,
home => $::tomcat::catalina_home_real,
system => true
Expand Down
25 changes: 21 additions & 4 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
# override service shutdown command
# [*tomcat_user*]
# service user
# [*tomcat_user_id*]
# service user id
# [*tomcat_group*]
# service group
# [*tomcat_group_id*]
# service group id
# [*file_mode*]
# mode for configuration files
# [*extras_enable*]
Expand Down Expand Up @@ -94,7 +98,9 @@
$service_start = undef,
$service_stop = undef,
$tomcat_user = $::tomcat::tomcat_user_real,
$tomcat_user_id = undef,
$tomcat_group = $::tomcat::tomcat_group_real,
$tomcat_group_id = undef,
$file_mode = '0600',
$extras_enable = false,
$extras_source = undef,
Expand Down Expand Up @@ -235,6 +241,7 @@
$host_undeployoldversions = undef,
$host_unpackwars = undef,
$host_params = {},
$hosts = {},
#..................................................................................
# host contexts
$contexts = [],
Expand Down Expand Up @@ -514,13 +521,21 @@
$security_manager_real = $security_manager ? {
true => 'yes',
default => 'no'
} } else {
}
} else {
$security_manager_real = $security_manager
}

$engine_defaulthost_real = $engine_defaulthost ? {
undef => $host_name,
default => $engine_defaulthost
if (empty($hosts)) {
$engine_defaulthost_real = $engine_defaulthost ? {
undef => $host_name,
default => $engine_defaulthost
}
} else {
$engine_defaulthost_real = $engine_defaulthost ? {
undef => $hosts[0]['name'],
default => $engine_defaulthost
}
}

$java_opts_real = join($java_opts, ' ')
Expand Down Expand Up @@ -655,13 +670,15 @@
if !defined(Group[$tomcat_group]) {
group { $tomcat_group:
ensure => present,
gid => $tomcat_group_id,
system => true
}
}

if !defined(User[$tomcat_user]) {
user { $tomcat_user:
ensure => present,
uid => $tomcat_user_id,
gid => $tomcat_group,
home => $catalina_home_real,
system => true
Expand Down
39 changes: 39 additions & 0 deletions templates/common/server.xml/091_hosts.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%- @hosts.each do |host| %>
<%- host.each_pair do |attrib, value| -%>
<%- if ! ['valves', 'contexts', 'aliases'].include? attrib -%>
<%- if attrib == host.keys.first -%>
<Host <%= attrib %>=<%= "#{value}".encode(:xml => :attr) -%>
<%- else %>
<%= attrib %>=<%= "#{value}".encode(:xml => :attr) -%>
<%- end -%>
<%- end -%>
<%- end -%>>
<%- if host['aliases'] and ! host['aliases'].empty? -%>
<%- host['aliases'].each do |al| -%>
<Alias><%= al %></Alias>
<%- end -%>
<%- end -%>
<%- if host['contexts'] and ! host['contexts'].empty? -%>
<%- host['contexts'].each do |context| -%>
<%- context.each_pair do |context_attrib, context_value| %>
<%- if context_attrib == context.keys.first -%>
<Context <%= context_attrib %>=<%= "#{context_value}".encode(:xml => :attr) -%>
<%- else -%>
<%= context_attrib %>=<%= "#{context_value}".encode(:xml => :attr) -%>
<%- end -%>
<%- end -%> />
<%- end -%>
<%- end -%>
<%- if host['valves'] and ! host['valves'].empty? -%>
<%- host['valves'].each do |valve| -%>
<%- valve.each_pair do |valve_attrib, valve_value| %>
<%- if valve_attrib == valve.keys.first -%>
<Valve <%= valve_attrib %>=<%= "#{valve_value}".encode(:xml => :attr) -%>
<%- else -%>
<%= valve_attrib %>=<%= "#{valve_value}".encode(:xml => :attr) -%>
<%- end -%>
<%- end -%> />
<%- end -%>
<%- end -%>
</Host>
<%- end -%>
2 changes: 2 additions & 0 deletions templates/common/server.xml/190_host_close.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

</Host>
2 changes: 0 additions & 2 deletions templates/common/server.xml/200_footer.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

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

0 comments on commit 479c149

Please sign in to comment.