Setting dynamic ttl from varnish headers in vcl

Objective: Turn “6m” into 6*60

set req.http.X-ttl = "60s"
...
call set_ttl
...
#set cached obj.ttl from req.url.X-ttl
sub set_ttl{
  #TODO
}

First version: converting “60s” to 60:

C{
  char *ttl;
  ttl = VRT_GetHdr(sp, HDR_OBJ, "\06X-ttl:"); // 6 == 6 chars
  VRT_l_obj_ttl(sp, atoi(ttl));
}C

Second version: use brute force to covert 60s + 60m + 60h

if( req.http.X-ttl ~ "s$"){ # seconds
  C{
    char *ttl;
    ttl = VRT_GetHdr(sp, HDR_REQ, "\06X-ttl:"); // 6 == 6 chars
    VRT_l_obj_ttl(sp, atoi(ttl));
  }C
} elseif ( req.http.X-ttl ~ "m$") { # minutes
  C{
    char *ttl;
    ttl = VRT_GetHdr(sp, HDR_REQ, "\06X-ttl:"); // 6 == 6 chars
    VRT_l_obj_ttl(sp, atoi(ttl) * 60);
  }C
} elseif ( req.http.X-ttl ~ "h$") { # hours
  C{
    char *ttl;
    ttl = VRT_GetHdr(sp, HDR_REQ, "\06X-ttl:"); // 6 == 6 chars
    VRT_l_obj_ttl(sp, atoi(ttl) * 60 * 60);
  }C
}

Third version: TODO

  • use TimeUnit from vcc_parse.c
  • build parser myself
  • ask for help in #varnish

If all else fails: Study the compiled C code: varnishd -d -f foo.vcl -C

SSL/HTTPS for Passenger in development on Ubuntu Jaunty

Making a certificate

sudo mkdir /etc/apache2/ssl
sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
sudo a2dissite default-ssl
sudo a2enmod ssl
sudo /etc/init.d/apache2 restart

Configure passenger

<VirtualHost *:80>
 ServerAlias *.something.com
 RailsEnv development
 DocumentRoot /apps/something/public
</VirtualHost>
<VirtualHost *:443>
 SSLEngine on
 SSLCertificateFile /etc/apache2/ssl/apache.pem
 ServerAlias *.something.com
 RailsEnv development
 DocumentRoot /apps/something/public
</VirtualHost>

host

Automated SSH Login with Password and Additional Commands

The normal answer to most ssh related problems is: “use public/private keys”
but sometimes this does not work…

What i did regularly was this:

  • ssh to xxx@asdads.com
  • enter password
  • sudo su admin
  • cd /apps/hosts/some_project

Thats not very complicated, but its frustrating. What I do now is: “sshxx”, which executes this excpect script in ~/bin/sshxx

#!/usr/bin/expect
set pass [lindex $argv 0] #get first argument
spawn ssh xxx@asdads.com
expect "assword" #matches Password and password
send "$pass\r"
expect "xxx@" #wait for the prompt
send "sudo su admin\r"
send "cd /apps/hosts/some_project\r"
send "clear\r" #clean up the mess
interact

(For Ubuntu you need to “sudo apt get install expect” first)