Puppet Class: varnish

Defined in:
manifests/init.pp

Overview

Class: varnish

Installs the varnish http accelerator and stops the varnishd and varnishlog services, because they are handled separately by varnish::instance.

Parameters:

  • multi_instances (Any) (defaults to: true)
  • vcl_content (Any) (defaults to: undef)
  • admin_listen_address (Any) (defaults to: undef)
  • admin_listen_port (Any) (defaults to: undef)
  • group (Any) (defaults to: undef)
  • listen_address (Any) (defaults to: undef)
  • listen_port (Any) (defaults to: undef)
  • secret_file (Any) (defaults to: undef)
  • storage (Any) (defaults to: undef)
  • ttl (Any) (defaults to: undef)
  • user (Any) (defaults to: undef)
  • vcl_conf (Any) (defaults to: '/etc/varnish/default.vcl')


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'manifests/init.pp', line 7

class varnish(
  $multi_instances = true,
  $vcl_content     = undef,

  $admin_listen_address = undef,
  $admin_listen_port    = undef,
  $group                = undef,
  $listen_address       = undef,
  $listen_port          = undef,
  $secret_file          = undef,
  $storage              = undef,
  $ttl                  = undef,
  $user                 = undef,
  $vcl_conf             = '/etc/varnish/default.vcl',
) {

  validate_bool($multi_instances)

  if ($multi_instances) {
    class { '::varnish::install': }

    service { 'varnish':
      ensure    => 'stopped',
      enable    => false,
      pattern   => '/var/run/varnishd.pid',
      hasstatus => false,
      require   => Package['varnish'],
    }

    service { 'varnishlog':
      ensure    => 'stopped',
      enable    => false,
      pattern   => '/var/run/varnishlog.pid',
      hasstatus => false,
      require   => Package['varnish'],
    }

    $module_path = get_module_path($module_name)
    file { '/usr/local/sbin/vcl-reload.sh':
      ensure  => file,
      owner   => 'root',
      group   => 'root',
      mode    => '0755',
      content => file("${module_path}/files/usr/local/sbin/vcl-reload.sh"),
    }

    case $::operatingsystem {
      'RedHat','CentOS','Amazon': {
        # By default RPM package fail to send HUP to varnishlog process, and don't
        # bother compressing rotated files. This fixes these issues, waiting for
        # this bug to get corrected upstream:
        # https://bugzilla.redhat.com/show_bug.cgi?id=554745
        augeas { 'logrotate config for varnishlog and varnishncsa':
          incl    => '/etc/logrotate.d/varnish',
          lens    => 'Logrotate.lns',
          changes => [
            'set /rule/schedule daily',
            'set /rule/rotate 7',
            'set /rule/compress compress',
            'set /rule/delaycompress delaycompress',
            'set /rule/postrotate "for service in varnishlog varnishncsa; do if /usr/bin/pgrep -P 1 $service >/dev/null; then /usr/bin/pkill -HUP $service 2>/dev/null; fi; done"',
          ],
          require => Package['varnish'],
        }
      }

      default: {}
    }
  } else {
    # New clean implementation
    class { '::varnish::install': } ->
    class { '::varnish::config_vcl': } ->
    class { '::varnish::config': } ~>
    class { '::varnish::service': } ->
    Class['varnish']
  }
}