Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Operating System: CentOS 6 (x86_64)

I have installed and configured varnish however it now is unable to start.

# service varnish restart
Stopping Varnish Cache:                                    [FAILED]
Starting Varnish Cache:                                    [FAILED]

I have narrowed this error down to the inclusion of another VCL file in /etc/varnish/default.vcl.

I include the VCL like so:

include "/etc/varnish/domains/playwithbits.vcl";

If I empty the contents of playwithbits.vcl then varnish is able to start, but as soon as I add contents it fails.

The contents of my playwithbits.vcl are:

backend playwithbits {
     .host = "localhost";
     .port = "8080";
}
acl purge {
     if (req.http.Host ~ "playwithbits.com") {
          "localhost";
     }
}
sub vcl_recv {
     if (req.http.Host ~ "playwithbits.com") {
          set req.backend = playwithbits; 
          if (req.request == "PURGE") {
               if (!client.ip ~ purge) {
                    error 405 "Not allowed.";
               }
               return(lookup);
          }
          if (req.url ~ "^/$") {
               unset req.http.cookie;
          }
     }
}
sub vcl_hit {
     if (req.http.Host ~ "playwithbits.com") {
          if (req.request == "PURGE") {
               set obj.ttl = 0s;
                    error 200 "Purged.";
          }
     }
}
sub vcl_miss {
     if (req.http.Host ~ "playwithbits.com") {
          if (req.request == "PURGE") {
               error 404 "Not in cache.";
          } 
          if (!(req.url ~ "wp-(login|admin)")) {
               unset req.http.cookie;
          }
          if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$") {
               unset req.http.cookie;
               set req.url = regsub(req.url, "\?.$", "");
          }
          if (req.url ~ "^/$") {
               unset req.http.cookie;
          }
     }
}
sub vcl_fetch {
     if (req.http.Host ~ "playwithbits.com") {
          if (req.url ~ "^/$") {
               unset beresp.http.set-cookie;
          }
          if (!(req.url ~ "wp-(login|admin)")) {
               unset beresp.http.set-cookie;
          }
     }
}

Here is the output of # strace -e trace=file service varnish start

execve("/sbin/service", ["service", "varnish", "start"], [/* 20 vars */]) = 0
access("/etc/ld.so.preload", R_OK)      = 0
open("/etc/ld.so.preload", O_RDONLY)    = 3
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib64/libtinfo.so.5", O_RDONLY)  = 3
open("/lib64/libdl.so.2", O_RDONLY)     = 3
open("/lib64/libc.so.6", O_RDONLY)      = 3
open("/dev/tty", O_RDWR|O_NONBLOCK)     = 3
open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
open("/proc/meminfo", O_RDONLY)         = 3
stat("/etc/varnish", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = 3
open("/sbin/service", O_RDONLY)         = 3
open("/etc/init.d/functions", O_RDONLY) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
stat("/etc/sysconfig/i18n", {st_mode=S_IFREG|0644, st_size=47, ...}) = 0
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
open("/etc/profile.d/lang.sh", O_RDONLY) = 3
stat("/root/.i18n", 0x7fff831f79e0)     = -1 ENOENT (No such file or directory)
stat("/etc/sysconfig/init", {st_mode=S_IFREG|0644, st_size=1153, ...}) = 0
open("/etc/sysconfig/init", O_RDONLY)   = 3
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/initscripts.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
chdir("/")                              = 0
stat("/etc/init.d/varnish", {st_mode=S_IFREG|0755, st_size=2837, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/sbin/env", 0x7fff831f8960)       = -1 ENOENT (No such file or directory)
stat("/usr/sbin/env", 0x7fff831f8960)   = -1 ENOENT (No such file or directory)
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
access("/bin/env", X_OK)                = 0
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
access("/bin/env", R_OK)                = 0
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
access("/bin/env", X_OK)                = 0
stat("/bin/env", {st_mode=S_IFREG|0755, st_size=23832, ...}) = 0
access("/bin/env", R_OK)                = 0
Starting Varnish Cache:                                    [FAILED]
--- SIGCHLD (Child exited) @ 0 (0) ---

Does anyone know what this issue is?

Solution:

The problem was with following block:

acl purge {
         if (req.http.Host ~ "playwithbits.com") {
              "localhost";
         }
    }

acl purge can only take strings as values, so if is invalid. Replaced with:

acl purge {
        "localhost";
        } 

And it works like a charm.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Start varnish with a good config (default.vcl?), and then try running a syntax check on your VCL before loading it. In varnish v2.1 (assuming similar in 3.x):

$ varnishadm -T 127.0.0.1:6082 

vcl.load error <path_to_your_vcl>
share|improve this answer
1  
Found the error sorted. Thanks –  George Reith Jun 14 '12 at 15:38
    
Great! What was it? (-: Do you mind posting how you solved it? –  KM. Jun 14 '12 at 17:55
    
Sure updated question with solution. –  George Reith Jun 14 '12 at 18:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.