Defined Type: varnish::instance

Defined in:
manifests/instance.pp

Overview

Definition: varnish::instance

Creates a running varnishd instance and configures it’s different startup parameters. Optionnally a VCL configuration file can be provided. Have a look at varnish.projects.linpro.no/wiki/Introduction for more details.

Parameters:

  • address: array of ip + port which varnish’s http service should bindto, defaults to all interfaces on port 80.

  • admin_address: address of varnish’s admin console, defaults to localhost.

  • admin_port: port of varnish’s admin console, defaults to 6082.

  • backend: location of the backend, in the “address:port” format. This is passed to “varnishd -b”. Defaults to none.

  • vcl_file: location of the instance’s VCL file, located on puppet’s fileserver (puppet://host/module/path.vcl). This is passed to “varnishd -f”. Defaults to none.

  • vcl_content: content of the instance’s VCL file. Defaults to none.

  • enable_secret: enable secret file in the instance’s configuration. Defaults to false.

  • secret_file: path to the secret file to use. Defaults to /etc/varnish/secret.

  • storage: array of backend “type” strings to be passed to “varnishd -s” since version 2.0 varnish support multiple storage files

  • params: array of “key=value” strings to be passed to “varnishd -p” (run-time parameters). Defaults to none.

  • nfiles: max number of open files (ulimit -n) allocated to varnishd, defaults to 131072.

  • memlock: max memory lock size (ulimit -l) allocated to varnishd, defaults to 82000.

  • corelimit: size of coredumps (ulimit -c). Usually “unlimited” or 0, defaults to 0.

  • varnishlog: whether a varnishlog instance must be run together with varnishd. defaults to true.

See varnishd(1) and /etc/default,sysconfig/varnish for more details.

Notes:

  • varnish’s configuration will be reloaded when it changes, using /usr/local/sbin/vcl-reload.sh

Requires:

  • Class

  • gcc if a VCL configuration file is used.

Example usage:

include varnish

varnish::instance { "foo":
  backend      => "10.0.0.2:8080",
  address      => ["192.168.1.10:80"],
  admin_port   => "6082",
  storage        => ["file,/var/varnish/storage1.bin,90%",
                     "file,/var/varnish/storage2.bin,90%"],
  params       => ["thread_pool_min=1",
                   "thread_pool_max=1000",
                   "thread_pool_timeout=120"],
}

varnish::instance { "bar":
  address    => ["192.168.1.11:80"],
  admin_port => "6083",
  vcl_file   => "puppet:///modules/barproject/varnish.vcl",
  corelimit  => "unlimited",
}

Parameters:

  • address (Any) (defaults to: [':80'])
  • admin_address (Any) (defaults to: 'localhost')
  • admin_port (Any) (defaults to: '6082')
  • backend (Any) (defaults to: false)
  • vcl_file (Any) (defaults to: false)
  • vcl_content (Any) (defaults to: false)
  • enable_secret (Any) (defaults to: false)
  • secret_file (Any) (defaults to: '/etc/varnish/secret')
  • storage (Any) (defaults to: [])
  • params (Any) (defaults to: [])
  • nfiles (Any) (defaults to: '131072')
  • memlock (Any) (defaults to: '82000')
  • corelimit (Any) (defaults to: '0')
  • varnishlog (Any) (defaults to: true)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'manifests/instance.pp', line 68

define varnish::instance(
  $address=[':80'],
  $admin_address='localhost',
  $admin_port='6082',
  $backend=false,
  $vcl_file=false,
  $vcl_content=false,
  $enable_secret=false,
  $secret_file='/etc/varnish/secret',
  $storage=[],
  $params=[],
  $nfiles='131072',
  $memlock='82000',
  $corelimit='0',
  $varnishlog=true
) {

  # use a more comprehensive attribute name for ERB templates.
  $instance = $name

  # All the startup options are defined in /etc/{default,sysconfig}/varnish-nnn
  $configfile_name = $::operatingsystem ? {
    /Debian|Ubuntu|kFreeBSD/        => "/etc/default/varnish-${instance}",
    /RedHat|Fedora|CentOS|Amazon/   => "/etc/sysconfig/varnish-${instance}",
  }

  file { "varnish-${instance} startup config":
    ensure  => file,
    content => template('varnish/varnish.erb'),
    name    => $configfile_name,
  }

  if ($vcl_file != false) {
    file { "/etc/varnish/${instance}.vcl":
      ensure  => file,
      source  => $vcl_file,
      owner   => 'root',
      group   => 'root',
      mode    => '0644',
      notify  => Service["varnish-${instance}"],
      require => Package['varnish'],
    }
  }

  if ($vcl_content != false) {
    file { "/etc/varnish/${instance}.vcl":
      ensure  => file,
      content => $vcl_content,
      notify  => Service["varnish-${instance}"],
      require => Package['varnish'],
    }
  }

  file { "/var/lib/varnish/${instance}":
    ensure  => directory,
    owner   => 'root',
    require => Package['varnish'],
  }

  $initscript_content = $::operatingsystem ? {
    /Debian|Ubuntu|kFreeBSD/      => template('varnish/varnish.debian.erb'),
    /RedHat|Fedora|CentOS|Amazon/ => template('varnish/varnish.redhat.erb'),
  }

  file { "/etc/init.d/varnish-${instance}":
    ensure  => file,
    mode    => '0755',
    owner   => 'root',
    group   => 'root',
    content => $initscript_content,
  }

  $log_initscript_content = $::operatingsystem ? {
    /Debian|Ubuntu|kFreeBSD/      => template('varnish/varnishlog.debian.erb'),
    /RedHat|Fedora|CentOS|Amazon/ => template('varnish/varnishlog.redhat.erb'),
  }

  file { "/etc/init.d/varnishlog-${instance}":
    ensure  => file,
    mode    => '0755',
    owner   => 'root',
    group   => 'root',
    content => $log_initscript_content,
  }

  $restart = $enable_secret ? {
    false => "/usr/local/sbin/vcl-reload.sh /etc/varnish/${instance}.vcl",
    true  => "/usr/local/sbin/vcl-reload.sh /etc/varnish/${instance}.vcl ${secret_file}",
  }

  service { "varnish-${instance}":
    ensure  => running,
    enable  => true,
    pattern => "/var/run/varnish-${instance}.pid",
    # reload VCL file when changed, without restarting the varnish service.
    restart => $restart,
    require => [
      File["/etc/init.d/varnish-${instance}"],
      File['/usr/local/sbin/vcl-reload.sh'],
      File["varnish-${instance} startup config"],
      File["/var/lib/varnish/${instance}"],
      Service['varnish'],
      Service['varnishlog']
    ],
  }

  if ($varnishlog == true ) {

    service { "varnishlog-${instance}":
      ensure    => running,
      enable    => true,
      pattern   => "/var/run/varnishlog-${instance}.pid",
      hasstatus => false,
      require   => [
        File["/etc/init.d/varnishlog-${instance}"],
        Service["varnish-${instance}"],
      ],
    }

  } else {

    service { "varnishlog-${instance}":
      ensure    => stopped,
      enable    => false,
      pattern   => "/var/run/varnishlog-${instance}.pid",
      hasstatus => false,
      require   => File["/etc/init.d/varnishlog-${instance}"],
    }
  }

}