|
| 1 | +# @summary |
| 2 | +# Installs and configures `mod_cache_disk`. |
| 3 | +# |
| 4 | +# @description |
| 5 | +# This will install an configure the proper module depending on the used apache version, so |
| 6 | +# - mod_cache_disk for apache version >= 2.4 |
| 7 | +# - mod_disk_cache for older apache versions |
| 8 | +# |
| 9 | +# @param cache_root |
| 10 | +# Defines the name of the directory on the disk to contain cache files. |
| 11 | +# Default depends on the Apache version and operating system: |
| 12 | +# - Debian: /var/cache/apache2/mod_cache_disk |
| 13 | +# - FreeBSD: /var/cache/mod_cache_disk |
| 14 | +# - Red Hat: /var/cache/httpd/proxy |
| 15 | +# |
| 16 | +# @param cache_enable |
| 17 | +# Defines an array of directories to cache, the default is none |
| 18 | +# |
| 19 | +# @param cache_dir_length |
| 20 | +# The number of characters in subdirectory names |
| 21 | +# |
| 22 | +# @param cache_dir_levels |
| 23 | +# The number of levels of subdirectories in the cache. |
| 24 | +# |
| 25 | +# @param cache_max_filesize |
| 26 | +# The maximum size (in bytes) of a document to be placed in the cache |
| 27 | +# |
| 28 | +# @param cache_ignore_headers |
| 29 | +# DEPRECATED Ignore request to not serve cached content to client (included for compatibility reasons to support disk_cache) |
| 30 | +# |
| 31 | +# @param configuration_file_name |
| 32 | +# DEPRECATED Name of module configuration file (used for the compatibility layer for disk_cache) |
| 33 | +# |
| 34 | +# @see https://httpd.apache.org/docs/2.4/mod/mod_cache_disk.html |
| 35 | +# |
| 36 | +class apache::mod::cache_disk ( |
| 37 | + Optional[Stdlib::Absolutepath] $cache_root = undef, |
| 38 | + Array[String] $cache_enable = [], |
| 39 | + Optional[Integer] $cache_dir_length = undef, |
| 40 | + Optional[Integer] $cache_dir_levels = undef, |
| 41 | + Optional[Integer] $cache_max_filesize = undef, |
| 42 | + Optional[String] $cache_ignore_headers = undef, |
| 43 | + Optional[String] $configuration_file_name = undef, |
| 44 | +) { |
| 45 | + include apache |
| 46 | + |
| 47 | + if $cache_ignore_headers { |
| 48 | + deprecation( |
| 49 | + 'apache::mod::cache_disk', |
| 50 | + 'The parameter cache_ignore_headers is deprecated. Please use apache::mod::cache::cache_ignore_headers instead.' |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + $_cache_root = $cache_root ? { |
| 55 | + undef => $facts['os']['family'] ? { |
| 56 | + 'debian' => '/var/cache/apache2/mod_cache_disk', |
| 57 | + 'redhat' => '/var/cache/httpd/proxy', |
| 58 | + 'freebsd' => '/var/cache/mod_cache_disk', |
| 59 | + }, |
| 60 | + default => $cache_root, |
| 61 | + } |
| 62 | + $_configuration_file_name = pick($configuration_file_name, 'cache_disk.conf') |
| 63 | + $_class_name = 'apache::mod::cache_disk' |
| 64 | + |
| 65 | + apache::mod { 'cache_disk': } |
| 66 | + |
| 67 | + Class['apache::mod::cache'] -> Class[$_class_name] |
| 68 | + |
| 69 | + file { $_configuration_file_name: |
| 70 | + ensure => file, |
| 71 | + path => "${apache::mod_dir}/${_configuration_file_name}", |
| 72 | + mode => $apache::file_mode, |
| 73 | + content => epp('apache/mod/cache_disk.conf.epp', { |
| 74 | + cache_root => $_cache_root, |
| 75 | + cache_enable => $cache_enable, |
| 76 | + cache_dir_length => $cache_dir_length, |
| 77 | + cache_dir_levels => $cache_dir_levels, |
| 78 | + cache_max_filesize => $cache_max_filesize, |
| 79 | + cache_ignore_headers => $cache_ignore_headers, |
| 80 | + }), |
| 81 | + require => Exec["mkdir ${apache::mod_dir}"], |
| 82 | + before => File[$apache::mod_dir], |
| 83 | + notify => Class['apache::service'], |
| 84 | + } |
| 85 | +} |
0 commit comments