Skip to content
Snippets Groups Projects
Commit 3ed70217 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

Allow multiple listen on same address.

Apache httpd does not allow you to listen on the same address/port
more than once, which makes abstracting virtual hosts a bit more
cumbersome, as you need to keep track of and listen on addresses
separately from each virtual host.  We here abstract away that, and
allow users to use apache::listen on the same URL multiple times.
Duplicates will then be removed before Apache httpd gets to see the
list of Listen directives.

The implementation now uses concat::file to manage a single include
file containing all the Listen directives, instead of including one
file for each apache::listen resource.  To create a list of unique
Listen directives, we use the 'filter' parameter of concat::file,
running 'sort | uniq'.
parent 759e0dc4
No related branches found
No related tags found
No related merge requests found
...@@ -22,16 +22,13 @@ ...@@ -22,16 +22,13 @@
* The address "www1" will _not_ be resolved to * The address "www1" will _not_ be resolved to
* an IP address. * an IP address.
* *
* Note that it is not possible to listen to the same address/port * It is permitted to listen to the same address/port combination more
* combination more than once, so named virtual hosts need to coordinate * than once using this definition. Duplicates will be removed from the
* the set of listening addresses between themselves. This is not * combined list of Listen directives generated before Apache httpd gets
* enforced by this definition, but by Apache. * to see them. (This is a new behaviour of this definition since 2024.)
* *
* To stop listening on a set of URLs, specify the 'ensure' parameter * To stop listening on a set of URLs, specify the 'ensure' parameter
* with the value 'absent'. If you just remove the apache::listen * with the value 'absent'.
* resource, the include file containing the Listen directives will be
* removed, but there will still be an Include directive referencing it,
* and Apache httpd will refuse to start!
*/ */
define apache::listen( define apache::listen(
...@@ -39,7 +36,7 @@ define apache::listen( ...@@ -39,7 +36,7 @@ define apache::listen(
$ensure = 'present', $ensure = 'present',
) )
{ {
include apache::listen::no_global_listen include apache::listen::common
case $ensure case $ensure
{ {
...@@ -47,15 +44,15 @@ define apache::listen( ...@@ -47,15 +44,15 @@ define apache::listen(
if ($urls == false) { if ($urls == false) {
fail("Apache::Listen[${title}]: Bad urls parameter, ${urls}") fail("Apache::Listen[${title}]: Bad urls parameter, ${urls}")
} }
apache::include_file { concat::part {
"_Listen_${name}": "${apache::listen::common::listen_cfgfile}/${name}":
ensure => $ensure, ensure => $ensure,
content => template('apache/listen.erb'); content => template('apache/listen.erb');
} }
} }
'absent': { 'absent': {
apache::include_file { concat::part {
"_Listen_${name}": "${apache::listen::common::listen_cfgfile}/${name}":
ensure => $ensure; ensure => $ensure;
} }
} }
...@@ -66,18 +63,40 @@ define apache::listen( ...@@ -66,18 +63,40 @@ define apache::listen(
} }
/* /*
* Internal helper class for apache::listen. * Internal helper class for apache::listen.
*/ */
class apache::listen::no_global_listen class apache::listen::common
{ {
include apache include apache
$listen_cfgfile = "${apache::configdir}/_Listen.conf"
cfgfile::comment_lines { cfgfile::comment_lines {
'apache::listen::no_global_listen': 'apache::listen::no_global_listen':
file => $apache::configfile, file => $apache::configfile,
pattern => '^\s*Listen(\s|$).*$', pattern => '^\s*Listen(\s|$).*$',
comment => '##--', comment => '##--',
require => Class[apache::base]; require => Class[apache::base],
notify => Class[apache::service];
}
concat::file {
$listen_cfgfile:
owner => 'root', group => 'root', mode => '0444',
filter => 'sort | uniq',
before => Apache::Include_file['_Listen'],
notify => Class[apache::service];
}
apache::include_file {
'_Listen':
ensure => 'onlyinclude';
}
delete_lines {
# Remove remains of old implementation
'apache::listen::common::single_listen_file':
file => $apache::configfile,
pattern => "\s*Include\s+conf\\.d/_Listen_.*\\.conf\s*$",
require => Class[apache::base],
notify => Class[apache::service];
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment