varnishcache-friends / libvmod-geoip2

Varnish VMOD to query MaxMind GeoIP2 DB files
BSD 2-Clause "Simplified" License
39 stars 17 forks source link

object country not initialized #41

Closed cjprinse closed 3 years ago

cjprinse commented 3 years ago

I installed the vmod from git, following all instructions. But I get the message: "Object country not initialized". What am I doing wrong?

vcl 4.1;
# Based on: https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl

import std;
import directors;
import cookie;
import header;
import geoip2;

backend server1 { # Define one backend
  .host = "web-dev";    # IP or Hostname of backend
  .port = "80";           # Port Apache or whatever is listening
  .max_connections = 500; # That's it
  .first_byte_timeout     = 300s;   # How long to wait before we receive a first byte from our backend?
  .connect_timeout        = 5s;     # How long to wait for a backend connection?
  .between_bytes_timeout  = 2s;     # How long to wait between bytes received from our backend?
}

sub vcl_init {
  new country = geoip2.geoip2("/usr/share/GeoIP/GeoLite2-Country.mmdb");

  # Called when VCL is loaded, before any requests pass through it.
  # Typically used to initialize VMODs.

  new vdir = directors.round_robin();
  vdir.add_backend(server1);
  # vdir.add_backend(server...);
  # vdir.add_backend(servern);
}
root@09b563a812cc:/# varnishd -F -f /etc/varnish/default.vcl
Warnings:
VCL compiled.

Debug: Version: varnish-6.6.0 revision ef54768fc10f5b19556c7cf9866efc88cfbda8ff
Debug: Platform: Linux,5.3.0-64-generic,x86_64,-jnone,-sdefault,-sdefault,-hcritbit
Debug: Child (25) Started
CLI result = 300
Error: Child (25) Pushing vcls failed:
VCL "boot" Failed initialization
Message:
    Object country not initialized

Debug: Stopping Child
Info: Child (25) ended
Info: Child (25) said Child starts
Info: Child (25) said Child dies
Debug: Child cleanup complete
fgsch commented 3 years ago

Hi. Thanks for the report. Let me have a look and I will get back to you.

fgsch commented 3 years ago

@cjprinse are you sure the file is readable by Varnish and is a valid Geoip2 database? The only case where country will not be initialised is if we cannot open the database.

In the meantime, I'd see if we can bubble up the error when we cannot open the database.

cjprinse commented 3 years ago

@fgsch Sorry for bothering you. It was a docker mount issue. Mounting the mmdb file as volume mount, turned out to be a directory in the container. I'm not mounting the directory above.

I got it working now :) Issue can be closed

fgsch commented 3 years ago

No worries, glad you got it working.