How to run dnscache with Upstart in Ubuntu

  1. First you’ll need to install djbdns package: apt-get install djbdns.
  2. Create user to run dnscache: adduser --system --no-create-home dnscache
  3. Create dnscache environment: dnscache-conf $(id -un) $(id -un) /tmp/dnscache (dnscache is intended to run with runit or daemontools, so environment dir is full of extra stuff which we do not need at all).
  4. Copy dnscache root directory to other place: cp -a /tmp/dnscache/root /etc/dnscache.
  5. Create upstart rule in file /etc/event.d/dnscache:

    description "Starts dnscache from djbdns package"
    start on runlevel 2
    start on runlevel 3
    stop on runlevel 0
    stop on runlevel 1
    stop on runlevel 4
    stop on runlevel 5
    stop on runlevel 6
    stop on shutdown
    console none
        export CACHESIZE=$((2*1024*1024))
        export DATALIMIT=$((32*1024*1024))
        export IP=
        export IPSEND=
        export ROOT=/etc/dnscache
        export UID=$(id -u dnscache)
        export GID=$(id -g dnscache)
        TMPFILE=$(tempfile -m0600)
        head -c128 /dev/urandom > $TMPFILE
        exec /usr/bin/dnscache
    end script
  6. Make sure dnscache is started: initctl list. If not, start it by running start dnscache.

  7. Now you’ve got your own local dns cache running on