From 33606abae3235a0316c269310c97462217637518 Mon Sep 17 00:00:00 2001 From: Chris Hacunda Date: Thu, 18 Jul 2024 18:10:42 -0400 Subject: [PATCH 1/3] unify Debian MPM management with mpm_ prefix --- manifests/mod/event.pp | 7 +- manifests/mod/itk.pp | 7 +- manifests/mod/prefork.pp | 7 +- manifests/mod/worker.pp | 7 +- manifests/mpm.pp | 165 ++++++++++++--------------- manifests/mpm/disable_mpm_event.pp | 17 +-- manifests/mpm/disable_mpm_prefork.pp | 17 +-- manifests/mpm/disable_mpm_worker.pp | 17 +-- spec/classes/mod/event_spec.rb | 64 +++++------ spec/classes/mod/itk_spec.rb | 12 +- spec/classes/mod/prefork_spec.rb | 10 +- spec/classes/mod/worker_spec.rb | 6 +- 12 files changed, 174 insertions(+), 162 deletions(-) diff --git a/manifests/mod/event.pp b/manifests/mod/event.pp index 42d646866c..864b50f4a1 100644 --- a/manifests/mod/event.pp +++ b/manifests/mod/event.pp @@ -86,7 +86,12 @@ 'listenbacklog' => $listenbacklog, } - file { "${apache::mod_dir}/event.conf": + $eventconffile = $facts['os']['family'] ? { + 'Debian' => "${apache::mod_dir}/mpm_event.conf", + default => "${apache::mod_dir}/event.conf", + } + + file { $eventconffile: ensure => file, mode => $apache::file_mode, content => epp('apache/mod/event.conf.epp', $parameters), diff --git a/manifests/mod/itk.pp b/manifests/mod/itk.pp index 96940d8593..80c0e62d78 100644 --- a/manifests/mod/itk.pp +++ b/manifests/mod/itk.pp @@ -79,7 +79,12 @@ 'enablecapabilities' => $enablecapabilities, } - file { "${apache::mod_dir}/itk.conf": + $itkconffile = $facts['os']['family'] ? { + 'Debian' => "${apache::mod_dir}/mpm_itk.conf", + default => "${apache::mod_dir}/itk.conf", + } + + file { $itkconffile: ensure => file, mode => $apache::file_mode, content => epp('apache/mod/itk.conf.epp', $parameters), diff --git a/manifests/mod/prefork.pp b/manifests/mod/prefork.pp index 1138d8314b..932e4e6801 100644 --- a/manifests/mod/prefork.pp +++ b/manifests/mod/prefork.pp @@ -79,7 +79,12 @@ 'listenbacklog' => $listenbacklog, } - file { "${apache::mod_dir}/prefork.conf": + $preforkconffile = $facts['os']['family'] ? { + 'Debian' => "${apache::mod_dir}/mpm_prefork.conf", + default => "${apache::mod_dir}/prefork.conf", + } + + file { $preforkconffile: ensure => file, content => epp('apache/mod/prefork.conf.epp', $parameters), require => Exec["mkdir ${apache::mod_dir}"], diff --git a/manifests/mod/worker.pp b/manifests/mod/worker.pp index 42fd52933f..537ab97582 100644 --- a/manifests/mod/worker.pp +++ b/manifests/mod/worker.pp @@ -90,7 +90,12 @@ 'maxrequestworkers' => $maxrequestworkers, } - file { "${apache::mod_dir}/worker.conf": + $workerconffile = $facts['os']['family'] ? { + 'Debian' => "${apache::mod_dir}/mpm_worker.conf", + default => "${apache::mod_dir}/worker.conf", + } + + file { $workerconffile: ensure => file, content => epp('apache/mod/worker.conf.epp', $parameters), require => Exec["mkdir ${apache::mod_dir}"], diff --git a/manifests/mpm.pp b/manifests/mpm.pp index d4b15853d2..867353c727 100644 --- a/manifests/mpm.pp +++ b/manifests/mpm.pp @@ -15,122 +15,105 @@ $_path = "${lib_path}/${_lib}" $_id = "mpm_${mpm}_module" - if $facts['os']['family'] == 'Suse' { - #mpms on Suse 12 don't use .so libraries so create a placeholder load file - file { "${mod_dir}/${mpm}.load": - ensure => file, - path => "${mod_dir}/${mpm}.load", - content => '', - require => [ - Package['httpd'], - Exec["mkdir ${mod_dir}"], - ], - before => File[$mod_dir], - notify => Class['apache::service'], + if $facts['os']['family'] == 'Debian' { + $mpm_modules = ['mpm_event', 'mpm_worker', 'mpm_prefork'] - "mpm_${mpm}" + $mpmloadfile = "${mod_dir}/mpm_${mpm}.load" + $mpmloadcontent = $mpm ? { + /(event|prefork|worker)/ => "# Conflicts: ${join($mpm_modules, ' ')}\nLoadModule ${_id} ${_path}\n", + 'itk' => "# Depends: mpm_prefork\nLoadModule ${_id} ${_path}\n", } } else { - file { "${mod_dir}/${mpm}.load": - ensure => file, - path => "${mod_dir}/${mpm}.load", - content => "LoadModule ${_id} ${_path}\n", - require => [ - Package['httpd'], - Exec["mkdir ${mod_dir}"], - ], - before => File[$mod_dir], - notify => Class['apache::service'], + $mpmloadfile = "${mod_dir}/${mpm}.load" + $mpmloadcontent = $facts['os']['family'] ? { + 'Suse' => '', + default => "LoadModule ${_id} ${_path}\n" } } + file { $mpmloadfile: + ensure => file, + path => $mpmloadfile, + content => $mpmloadcontent, + require => [ + Package['httpd'], + Exec["mkdir ${mod_dir}"], + ], + before => File[$mod_dir], + notify => Class['apache::service'], + } + case $facts['os']['family'] { - 'Debian': { - file { "${apache::mod_enable_dir}/${mpm}.conf": - ensure => link, - target => "${apache::mod_dir}/${mpm}.conf", - require => Exec["mkdir ${apache::mod_enable_dir}"], - before => File[$apache::mod_enable_dir], - notify => Class['apache::service'], + 'Debian', 'Suse': { + $mpm_filename = $facts['os']['family'] ? { + 'Debian' => "mpm_${mpm}", + default => $mpm, } - file { "${apache::mod_enable_dir}/${mpm}.load": - ensure => link, - target => "${apache::mod_dir}/${mpm}.load", - require => Exec["mkdir ${apache::mod_enable_dir}"], - before => File[$apache::mod_enable_dir], - notify => Class['apache::service'], + file { + default: + ensure => link, + require => Exec["mkdir ${apache::mod_enable_dir}"], + before => File[$apache::mod_enable_dir], + notify => Class['apache::service'], + ; + "${apache::mod_enable_dir}/${mpm_filename}.conf": + target => "../mods-available/${mpm_filename}.conf", + ; + "${apache::mod_enable_dir}/${mpm_filename}.load": + target => "../mods-available/${mpm_filename}.load", + ; } - if $mpm == 'itk' { - file { "${lib_path}/mod_mpm_itk.so": - ensure => link, - target => "${lib_path}/mpm_itk.so", - require => Package['httpd'], - before => Class['apache::service'], + if $facts['os']['family'] == 'Debian' { + if $mpm == 'itk' { + file { "${lib_path}/mod_mpm_itk.so": + ensure => link, + target => "${lib_path}/mpm_itk.so", + require => Package['httpd'], + before => Class['apache::service'], + } + + package { 'libapache2-mpm-itk': + ensure => present, + before => [ + Class['apache::service'], + File[$apache::mod_enable_dir], + ], + } } - } - if $mpm == 'itk' { - package { 'libapache2-mpm-itk': - ensure => present, - before => [ - Class['apache::service'], - File[$apache::mod_enable_dir], - ], + unless $mpm in ['itk', 'prefork'] { + include apache::mpm::disable_mpm_prefork } - } - unless $mpm in ['itk', 'prefork'] { - include apache::mpm::disable_mpm_prefork - } + if $mpm != 'worker' { + include apache::mpm::disable_mpm_worker + } - if $mpm != 'worker' { - include apache::mpm::disable_mpm_worker - } + if $mpm != 'event' { + include apache::mpm::disable_mpm_event + } + } else { + if $mpm == 'itk' { + file { "${lib_path}/mod_mpm_itk.so": + ensure => link, + target => "${lib_path}/mpm_itk.so", + } + } - if $mpm != 'event' { - include apache::mpm::disable_mpm_event + package { "apache2-${mpm}": + ensure => present, + } } } - 'FreeBSD': { class { 'apache::package': mpm_module => $mpm, } } - 'Gentoo': { - # so we don't fail - } - 'RedHat': { + 'Gentoo', 'RedHat': { # so we don't fail } - 'Suse': { - file { "${apache::mod_enable_dir}/${mpm}.conf": - ensure => link, - target => "${apache::mod_dir}/${mpm}.conf", - require => Exec["mkdir ${apache::mod_enable_dir}"], - before => File[$apache::mod_enable_dir], - notify => Class['apache::service'], - } - - file { "${apache::mod_enable_dir}/${mpm}.load": - ensure => link, - target => "${apache::mod_dir}/${mpm}.load", - require => Exec["mkdir ${apache::mod_enable_dir}"], - before => File[$apache::mod_enable_dir], - notify => Class['apache::service'], - } - - if $mpm == 'itk' { - file { "${lib_path}/mod_mpm_itk.so": - ensure => link, - target => "${lib_path}/mpm_itk.so", - } - } - - package { "apache2-${mpm}": - ensure => present, - } - } default: { fail("Unsupported osfamily ${$facts['os']['family']}") } diff --git a/manifests/mpm/disable_mpm_event.pp b/manifests/mpm/disable_mpm_event.pp index faa04cfe8f..d2b2dc6fae 100644 --- a/manifests/mpm/disable_mpm_event.pp +++ b/manifests/mpm/disable_mpm_event.pp @@ -1,11 +1,14 @@ # @summary disable Apache-Module event class apache::mpm::disable_mpm_event { - $event_command = ['/usr/sbin/a2dismod', 'mpm_event'] - $event_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, 'mpm_event.load'],'/')]] - exec { '/usr/sbin/a2dismod mpm_event': - command => $event_command, - onlyif => $event_onlyif, - require => Package['httpd'], - notify => Class['apache::service'], + $mod_names = ['event', 'mpm_event'] + $mod_names.each | $mod_name| { + $event_command = ['/usr/sbin/a2dismod', $mod_name] + $event_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, "${mod_name}.load"],'/')]] + exec { "/usr/sbin/a2dismod ${mod_name}": + command => $event_command, + onlyif => $event_onlyif, + require => Package['httpd'], + notify => Class['apache::service'], + } } } diff --git a/manifests/mpm/disable_mpm_prefork.pp b/manifests/mpm/disable_mpm_prefork.pp index 1488276915..57be16e361 100644 --- a/manifests/mpm/disable_mpm_prefork.pp +++ b/manifests/mpm/disable_mpm_prefork.pp @@ -1,11 +1,14 @@ # @summary disable Apache-Module prefork class apache::mpm::disable_mpm_prefork { - $prefork_command = ['/usr/sbin/a2dismod', 'prefork'] - $prefork_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, 'prefork.load'],'/')]] - exec { '/usr/sbin/a2dismod prefork': - command => $prefork_command, - onlyif => $prefork_onlyif, - require => Package['httpd'], - before => Class['apache::service'], + $mod_names = ['itk', 'mpm_itk', 'prefork', 'mpm_prefork'] + $mod_names.each | $mod_name| { + $prefork_command = ['/usr/sbin/a2dismod', $mod_name] + $prefork_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, "${mod_name}.load"],'/')]] + exec { "/usr/sbin/a2dismod ${mod_name}": + command => $prefork_command, + onlyif => $prefork_onlyif, + require => Package['httpd'], + notify => Class['apache::service'], + } } } diff --git a/manifests/mpm/disable_mpm_worker.pp b/manifests/mpm/disable_mpm_worker.pp index 7da4a92ace..9f70c5b057 100644 --- a/manifests/mpm/disable_mpm_worker.pp +++ b/manifests/mpm/disable_mpm_worker.pp @@ -1,11 +1,14 @@ # @summary disable Apache-Module worker class apache::mpm::disable_mpm_worker { - $worker_command = ['/usr/sbin/a2dismod', 'worker'] - $worker_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, 'worker.load'],'/')]] - exec { '/usr/sbin/a2dismod worker': - command => $worker_command, - onlyif => $worker_onlyif, - require => Package['httpd'], - before => Class['apache::service'], + $mod_names = ['worker', 'mpm_worker'] + $mod_names.each | $mod_name| { + $worker_command = ['/usr/sbin/a2dismod', $mod_name] + $worker_onlyif = [['/usr/bin/test', '-e', join([$apache::mod_enable_dir, "${mod_name}.load"],'/')]] + exec { "/usr/sbin/a2dismod ${mod_name}": + command => $worker_command, + onlyif => $worker_onlyif, + require => Package['httpd'], + notify => Class['apache::service'], + } } } diff --git a/spec/classes/mod/event_spec.rb b/spec/classes/mod/event_spec.rb index 39d83ae992..ca45b86a90 100644 --- a/spec/classes/mod/event_spec.rb +++ b/spec/classes/mod/event_spec.rb @@ -28,8 +28,8 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('event') } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file') } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/event.conf').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_event.conf').with_ensure('link') } context 'Test mpm_event new params' do let :params do @@ -46,15 +46,15 @@ } end - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ServerLimit\s*0}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*StartServers\s*1}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MinSpareThreads\s*3}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MaxSpareThreads\s*4}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ThreadsPerChild\s*5}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ThreadLimit\s*7}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ListenBacklog\s*8}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MaxRequestWorkers\s*9}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MaxConnectionsPerChild\s*10}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ServerLimit\s*0}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*StartServers\s*1}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MinSpareThreads\s*3}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MaxSpareThreads\s*4}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ThreadsPerChild\s*5}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ThreadLimit\s*7}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ListenBacklog\s*8}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MaxRequestWorkers\s*9}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MaxConnectionsPerChild\s*10}) } end context 'Test mpm_event old style params' do @@ -72,15 +72,15 @@ } end - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ServerLimit\s*0}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*StartServers\s*1}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MinSpareThreads\s*3}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*MaxSpareThreads\s*4}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ThreadsPerChild\s*5}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ThreadLimit\s*7}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').with_content(%r{^\s*ListenBacklog\s*8}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MaxRequestWorkers}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MaxConnectionsPerChild}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ServerLimit\s*0}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*StartServers\s*1}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MinSpareThreads\s*3}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*MaxSpareThreads\s*4}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ThreadsPerChild\s*5}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ThreadLimit\s*7}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').with_content(%r{^\s*ListenBacklog\s*8}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MaxRequestWorkers}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MaxConnectionsPerChild}) } end context 'Test mpm_event false params' do @@ -98,23 +98,23 @@ } end - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*ServerLimit}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*StartServers}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MinSpareThreads}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MaxSpareThreads}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*ThreadsPerChild}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*ThreadLimit}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*ListenBacklog}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MaxRequestWorkers}) } - it { is_expected.to contain_file('/etc/apache2/mods-available/event.conf').with_ensure('file').without_content(%r{^\s*MaxConnectionsPerChild}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*ServerLimit}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*StartServers}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MinSpareThreads}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MaxSpareThreads}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*ThreadsPerChild}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*ThreadLimit}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*ListenBacklog}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MaxRequestWorkers}) } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_event.conf').with_ensure('file').without_content(%r{^\s*MaxConnectionsPerChild}) } end it { - expect(subject).to contain_file('/etc/apache2/mods-available/event.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/mpm_event.load').with('ensure' => 'file', + 'content' => "# Conflicts: mpm_worker mpm_prefork\nLoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n") } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/event.load').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_event.load').with_ensure('link') } end context 'on a RedHat OS' do diff --git a/spec/classes/mod/itk_spec.rb b/spec/classes/mod/itk_spec.rb index 2ecf14f76f..d31ee896f9 100644 --- a/spec/classes/mod/itk_spec.rb +++ b/spec/classes/mod/itk_spec.rb @@ -12,8 +12,8 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('itk') } - it { is_expected.to contain_file('/etc/apache2/mods-available/itk.conf').with_ensure('file') } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/itk.conf').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_itk.conf').with_ensure('file') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_itk.conf').with_ensure('link') } context 'with prefork mpm' do let :pre_condition do @@ -21,11 +21,11 @@ end it { - expect(subject).to contain_file('/etc/apache2/mods-available/itk.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/mpm_itk.load').with('ensure' => 'file', + 'content' => "# Depends: mpm_prefork\nLoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n") } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/itk.load').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_itk.load').with_ensure('link') } end context 'with enablecapabilities not set' do @@ -33,7 +33,7 @@ 'class { "apache": mpm_module => prefork, }' end - it { is_expected.not_to contain_file('/etc/apache2/mods-available/itk.conf').with_content(%r{EnableCapabilities}) } + it { is_expected.not_to contain_file('/etc/apache2/mods-available/mpm_itk.conf').with_content(%r{EnableCapabilities}) } end end diff --git a/spec/classes/mod/prefork_spec.rb b/spec/classes/mod/prefork_spec.rb index 0ebe44794a..9344d769d0 100644 --- a/spec/classes/mod/prefork_spec.rb +++ b/spec/classes/mod/prefork_spec.rb @@ -12,15 +12,15 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('prefork') } - it { is_expected.to contain_file('/etc/apache2/mods-available/prefork.conf').with_ensure('file') } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/prefork.conf').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_prefork.conf').with_ensure('file') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_prefork.conf').with_ensure('link') } it { - expect(subject).to contain_file('/etc/apache2/mods-available/prefork.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/mpm_prefork.load').with('ensure' => 'file', + 'content' => "# Conflicts: mpm_event mpm_worker\nLoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n") } - it { is_expected.to contain_file('/etc/apache2/mods-enabled/prefork.load').with_ensure('link') } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_prefork.load').with_ensure('link') } end context 'on a RedHat OS' do diff --git a/spec/classes/mod/worker_spec.rb b/spec/classes/mod/worker_spec.rb index 3377c9fd2f..f2cf885cea 100644 --- a/spec/classes/mod/worker_spec.rb +++ b/spec/classes/mod/worker_spec.rb @@ -12,11 +12,11 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('worker') } - it { is_expected.to contain_file('/etc/apache2/mods-available/worker.conf').with_ensure('file') } + it { is_expected.to contain_file('/etc/apache2/mods-available/mpm_worker.conf').with_ensure('file') } it { - expect(subject).to contain_file('/etc/apache2/mods-available/worker.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/mpm_worker.load').with('ensure' => 'file', + 'content' => "# Conflicts: mpm_event mpm_prefork\nLoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n") } end From 4e9fcb7c79037375b20a8b2cef16a87c5ea9d4f6 Mon Sep 17 00:00:00 2001 From: Chris Hacunda Date: Fri, 19 Jul 2024 15:08:52 -0400 Subject: [PATCH 2/3] separate Debian and SUSE logic for mpm management --- manifests/mpm.pp | 95 ++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/manifests/mpm.pp b/manifests/mpm.pp index 867353c727..4ab38676ba 100644 --- a/manifests/mpm.pp +++ b/manifests/mpm.pp @@ -43,12 +43,7 @@ } case $facts['os']['family'] { - 'Debian', 'Suse': { - $mpm_filename = $facts['os']['family'] ? { - 'Debian' => "mpm_${mpm}", - default => $mpm, - } - + 'Debian': { file { default: ensure => link, @@ -56,55 +51,69 @@ before => File[$apache::mod_enable_dir], notify => Class['apache::service'], ; - "${apache::mod_enable_dir}/${mpm_filename}.conf": - target => "../mods-available/${mpm_filename}.conf", + "${apache::mod_enable_dir}/mpm_${mpm}.conf": + target => "../mods-available/mpm_${mpm}.conf", ; - "${apache::mod_enable_dir}/${mpm_filename}.load": - target => "../mods-available/${mpm_filename}.load", + "${apache::mod_enable_dir}/mpm_${mpm}.load": + target => "../mods-available/mpm_${mpm}.load", ; } - if $facts['os']['family'] == 'Debian' { - if $mpm == 'itk' { - file { "${lib_path}/mod_mpm_itk.so": - ensure => link, - target => "${lib_path}/mpm_itk.so", - require => Package['httpd'], - before => Class['apache::service'], - } - - package { 'libapache2-mpm-itk': - ensure => present, - before => [ - Class['apache::service'], - File[$apache::mod_enable_dir], - ], - } + if $mpm == 'itk' { + file { "${lib_path}/mod_mpm_itk.so": + ensure => link, + target => "${lib_path}/mpm_itk.so", + require => Package['httpd'], + before => Class['apache::service'], } - unless $mpm in ['itk', 'prefork'] { - include apache::mpm::disable_mpm_prefork + package { 'libapache2-mpm-itk': + ensure => present, + before => [ + Class['apache::service'], + File[$apache::mod_enable_dir], + ], } + } - if $mpm != 'worker' { - include apache::mpm::disable_mpm_worker - } + unless $mpm in ['itk', 'prefork'] { + include apache::mpm::disable_mpm_prefork + } - if $mpm != 'event' { - include apache::mpm::disable_mpm_event - } - } else { - if $mpm == 'itk' { - file { "${lib_path}/mod_mpm_itk.so": - ensure => link, - target => "${lib_path}/mpm_itk.so", - } - } + if $mpm != 'worker' { + include apache::mpm::disable_mpm_worker + } - package { "apache2-${mpm}": - ensure => present, + if $mpm != 'event' { + include apache::mpm::disable_mpm_event + } + } + 'Suse': { + file { + default: + ensure => link, + require => Exec["mkdir ${apache::mod_enable_dir}"], + before => File[$apache::mod_enable_dir], + notify => Class['apache::service'], + ; + "${apache::mod_enable_dir}/${mpm}.conf": + target => "${mod_dir}/${mpm}.conf", + ; + "${apache::mod_enable_dir}/${mpm}.load": + target => "${mod_dir}/${mpm}.load", + ; + } + + if $mpm == 'itk' { + file { "${lib_path}/mod_mpm_itk.so": + ensure => link, + target => "${lib_path}/mpm_itk.so", } } + + package { "apache2-${mpm}": + ensure => present, + } } 'FreeBSD': { class { 'apache::package': From f26b37c2ca0f5cc2b661bc80fec8daffd17a39b8 Mon Sep 17 00:00:00 2001 From: Chris Hacunda Date: Fri, 19 Jul 2024 15:09:23 -0400 Subject: [PATCH 3/3] break long string apart to fix rubocop warnings --- spec/classes/mod/event_spec.rb | 6 +++++- spec/classes/mod/itk_spec.rb | 6 +++++- spec/classes/mod/prefork_spec.rb | 6 +++++- spec/classes/mod/worker_spec.rb | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/classes/mod/event_spec.rb b/spec/classes/mod/event_spec.rb index ca45b86a90..4a4697174e 100644 --- a/spec/classes/mod/event_spec.rb +++ b/spec/classes/mod/event_spec.rb @@ -25,6 +25,10 @@ context 'on a Debian OS' do include_examples 'Debian 11' + let(:loadcontent) do + "# Conflicts: mpm_worker mpm_prefork\n"\ + "LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n" + end it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('event') } @@ -111,7 +115,7 @@ it { expect(subject).to contain_file('/etc/apache2/mods-available/mpm_event.load').with('ensure' => 'file', - 'content' => "# Conflicts: mpm_worker mpm_prefork\nLoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n") + 'content' => loadcontent) } it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_event.load').with_ensure('link') } diff --git a/spec/classes/mod/itk_spec.rb b/spec/classes/mod/itk_spec.rb index d31ee896f9..74b77ce75e 100644 --- a/spec/classes/mod/itk_spec.rb +++ b/spec/classes/mod/itk_spec.rb @@ -9,6 +9,10 @@ context 'on a Debian OS' do include_examples 'Debian 11' + let(:loadcontent) do + "# Depends: mpm_prefork\n"\ + "LoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n" + end it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('itk') } @@ -22,7 +26,7 @@ it { expect(subject).to contain_file('/etc/apache2/mods-available/mpm_itk.load').with('ensure' => 'file', - 'content' => "# Depends: mpm_prefork\nLoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n") + 'content' => loadcontent) } it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_itk.load').with_ensure('link') } diff --git a/spec/classes/mod/prefork_spec.rb b/spec/classes/mod/prefork_spec.rb index 9344d769d0..ade98373be 100644 --- a/spec/classes/mod/prefork_spec.rb +++ b/spec/classes/mod/prefork_spec.rb @@ -9,6 +9,10 @@ context 'on a Debian OS' do include_examples 'Debian 11' + let(:loadcontent) do + "# Conflicts: mpm_event mpm_worker\n"\ + "LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n" + end it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('prefork') } @@ -17,7 +21,7 @@ it { expect(subject).to contain_file('/etc/apache2/mods-available/mpm_prefork.load').with('ensure' => 'file', - 'content' => "# Conflicts: mpm_event mpm_worker\nLoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n") + 'content' => loadcontent) } it { is_expected.to contain_file('/etc/apache2/mods-enabled/mpm_prefork.load').with_ensure('link') } diff --git a/spec/classes/mod/worker_spec.rb b/spec/classes/mod/worker_spec.rb index f2cf885cea..c81499e26b 100644 --- a/spec/classes/mod/worker_spec.rb +++ b/spec/classes/mod/worker_spec.rb @@ -9,6 +9,10 @@ context 'on a Debian OS' do include_examples 'Debian 11' + let(:loadcontent) do + "# Conflicts: mpm_event mpm_prefork\n"\ + "LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n" + end it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('worker') } @@ -16,7 +20,7 @@ it { expect(subject).to contain_file('/etc/apache2/mods-available/mpm_worker.load').with('ensure' => 'file', - 'content' => "# Conflicts: mpm_event mpm_prefork\nLoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n") + 'content' => loadcontent) } end