sallinen varnish
authorPeter Palfrader <peter@palfrader.org>
Mon, 28 May 2018 08:37:24 +0000 (10:37 +0200)
committerPeter Palfrader <peter@palfrader.org>
Mon, 28 May 2018 08:39:37 +0000 (10:39 +0200)
modules/roles/manifests/snapshot_web.pp
modules/roles/templates/snapshot/snapshot.debian.org.vcl.erb [new file with mode: 0644]
modules/varnish/manifests/config.pp [new file with mode: 0644]

index c3eeddd..be3039c 100644 (file)
@@ -12,4 +12,26 @@ class roles::snapshot_web {
                site   => 'snapshot.debian.org',
                content => template('roles/snapshot/snapshot.debian.org.conf.erb')
        }
+
+       case $::hostname {
+               'sallinen': {
+                       varnish::default { 'default':
+                               listen  => ':6081,[2001:630:206:4000:1a1a:0:c13e:ca1b]:80',
+                               backend => 'file,/var/lib/varnish/varnish_storage.bin,8G',
+                               content => template('roles/snapshot/snapshot.debian.org.vcl.erb'),
+                       }
+
+                       file { '/etc/apache2/ports.conf':
+                               content  => @("EOF"),
+                                       Listen 0.0.0.0:80
+                                       Listen [2001:630:206:4000:1a1a:0:c13e:ca1a]:80
+                                       | EOF
+                               require => Package['apache2'],
+                               notify  => Service['apache2'],
+                       }
+               }
+               default: {
+                       fail ( "unknown host $::hostname for snapshot_web." )
+               }
+       }
 }
diff --git a/modules/roles/templates/snapshot/snapshot.debian.org.vcl.erb b/modules/roles/templates/snapshot/snapshot.debian.org.vcl.erb
new file mode 100644 (file)
index 0000000..25e6d12
--- /dev/null
@@ -0,0 +1,27 @@
+#-e This is a basic VCL configuration file for varnish.  See the vcl(7)
+#man page for details on VCL syntax and semantics.
+vcl 4.0;
+
+backend default {
+ .host = "127.0.0.1";
+ .port = "80";
+}
+
+# weasel's rule:
+sub vcl_recv {
+ if (req.http.Cache-Control ~ "(?i)no-cache") {
+   # Ignore requests via proxy caches and badly behaved crawlers
+   if (! (req.http.Via || req.http.User-Agent ~ "(?i)bot" || req.http.X-Purge)) {
+      return(purge); # Couple this with restart in vcl_purge and X-Purge header to avoid loops
+   }
+ }
+}
+
+sub vcl_purge {
+  # Only handle actual PURGE HTTP methods, everything else is discarded
+  if (req.method != "PURGE") {
+    # restart request
+    set req.http.X-Purge = "Yes";
+    return(restart);
+  }
+}
diff --git a/modules/varnish/manifests/config.pp b/modules/varnish/manifests/config.pp
new file mode 100644 (file)
index 0000000..a46f799
--- /dev/null
@@ -0,0 +1,47 @@
+define varnish::config (
+       $listen = ':6081',
+       $source=undef,
+       $content=undef,
+       $ensure = 'present',
+       $backend = "-s malloc,256m",
+) {
+       if $name != "default" {
+               fail ( "This module cannot setup non-default varnish instances yet." )
+       }
+
+       case $ensure {
+               present: {
+                       include varnish::base
+
+                       if ! ($source or $content) {
+                               fail ( "No configuration found for ${name}" )
+                       }
+
+                       systemd::override { 'varnish':
+                               content  => @("EOF"),
+                                       [Service]
+                                       ExecStart=
+                                       ExecStart=/usr/sbin/varnishd -a ${listen} -T localhost:6082 -f /etc/varnish/${name}.vcl -S /etc/varnish/secret -s ${backend}
+                                       | EOF
+                       }
+
+                       $dest = "/etc/varnish/${name}.vcl"
+                       if $content {
+                               file { "${dest}":
+                                       ensure  => $ensure,
+                                       content => $content,
+                                       notify  => Service["varnish"],
+                               }
+                       } elsif $source {
+                               file { "${dest}":
+                                       ensure  => $ensure,
+                                       source  => $source,
+                                       notify  => Service["varnish"],
+                                       }
+                       }
+               }
+               default: {
+                       fail ( "Can only deal with ensure=>present for now" )
+               }
+       }
+}