start varnish only after network is online
[mirror/dsa-puppet.git] / modules / varnish / manifests / config.pp
1 define varnish::config (
2         $listen = [':6081'],
3         $source=undef,
4         $content=undef,
5         $ensure = 'present',
6         $backend = "-s malloc,256m",
7 ) {
8         if $name != "default" {
9                 fail ( "This module cannot setup non-default varnish instances yet." )
10         }
11
12         case $ensure {
13                 present: {
14                         include varnish::base
15                         include stretch::network_online
16
17                         if ! ($source or $content) {
18                                 fail ( "No configuration found for ${name}" )
19                         }
20
21                         $listenarr = [] + $listen
22                         $listenstr = join(prefix($listenarr, "-a "), " ")
23                         systemd::override { 'varnish':
24                                 content  => @("EOF"),
25                                         [Unit]
26                                         After=network-online.target
27                                         [Service]
28                                         ExecStart=
29                                         ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F ${listenstr} -T localhost:6082 -f /etc/varnish/${name}.vcl -S /etc/varnish/secret -s ${backend}
30                                         | EOF
31                         }
32
33                         $dest = "/etc/varnish/${name}.vcl"
34                         if $content {
35                                 file { "${dest}":
36                                         ensure  => $ensure,
37                                         content => $content,
38                                         notify  => Service["varnish"],
39                                 }
40                         } elsif $source {
41                                 file { "${dest}":
42                                         ensure  => $ensure,
43                                         source  => $source,
44                                         notify  => Service["varnish"],
45                                         }
46                         }
47                 }
48                 default: {
49                         fail ( "Can only deal with ensure=>present for now" )
50                 }
51         }
52 }