Index: Portfile
===================================================================
--- Portfile	(revision 107152)
+++ Portfile	(working copy)
@@ -1,25 +1,71 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 # $Id$
 
-PortSystem	      1.0
+PortSystem            1.0
 
-name		      varnish
-epoch                 20110709
-version               3.0.3
-categories	      www
-license               BSD zlib
-platforms	      darwin
-maintainers	      pmq openmaintainer
+name                  varnish
+version               3.0.4
+categories            www
+platforms             darwin
+maintainers           pmq openmaintainer
+license               BSD
 
-description	      Varnish is a state-of-the-art, high-performance HTTP accelerator
+description           Varnish is a state-of-the-art, high-performance HTTP accelerator
 long_description      Varnish was written from the ground up to be a high \
-		      performance caching reverse proxy.
+                      performance caching reverse proxy.
 
-homepage	      http://www.varnish-cache.org
-master_sites	      http://repo.varnish-cache.org/source/
+homepage              http://www.varnish-cache.org
+master_sites          http://repo.varnish-cache.org/source/
 
-checksums             rmd160 a911a2637ef26607aad8a1c34a83bc797a15235d \
-                      sha256 2d37d18d952f58b208ac3a0706d4d3e4c0de304b1fcc9df5019571c75f148ab2
+checksums             rmd160  ed8aba21af17d5fee225eb03950fd90ad7b07911 \
+                      sha256  4e044ccb5c76222bddf89c808f13ea8f66977972675aecb48a920f6800ad0f79
 
-depends_build         port:pkgconfig
+depends_build         port:pkgconfig \
+                      port:py27-docutils
 
 depends_lib           port:pcre
+
+configure.args-append --with-rst2man=${prefix}/bin/rst2man-2.7.py
+
+startupitem.create    yes
+startupitem.pidfile   auto "${prefix}/var/run/${name}/${name}.pid"
+startupitem.start     "${prefix}/share/${name}/varnish.init start"
+startupitem.stop      "${prefix}/share/${name}/varnish.init stop"
+startupitem.restart   "${prefix}/share/${name}/varnish.init restart"
+
+post-destroot {
+    # create dir
+    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
+
+    # copy files
+    xinstall -m 644 ${filespath}/varnish.conf.in ${destroot}${prefix}/etc/${name}/varnish.conf.default
+    xinstall -m 755 ${filespath}/varnish.init.in ${destroot}${prefix}/share/${name}/${name}.init
+    xinstall -m 755 ${filespath}/varnish-vcl-reload.in ${destroot}${prefix}/sbin/varnish-vcl-reload
+
+    # replace @PREFIX@ to ${prefix}
+    reinplace "s|@PREFIX@|${prefix}|g" \
+        ${destroot}${prefix}/etc/${name}/varnish.conf.default \
+        ${destroot}${prefix}/share/${name}/${name}.init \
+        ${destroot}${prefix}/sbin/varnish-vcl-reload
+
+    file rename ${destroot}${prefix}/etc/${name}/default.vcl ${destroot}${prefix}/etc/${name}/default.vcl.default
+}
+
+post-activate {
+    if {![file exists ${prefix}/etc/${name}/default.vcl]} {
+        file copy ${prefix}/etc/${name}/default.vcl.default \
+            ${prefix}/etc/${name}/default.vcl
+    }
+    if {![file exists ${prefix}/etc/${name}/varnish.conf]} {
+        file copy ${prefix}/etc/${name}/varnish.conf.default \
+            ${prefix}/etc/${name}/varnish.conf
+    }
+
+    # dirs nedded to run varnish
+    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/${name}
+    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/run/${name}
+}
+
+livecheck.url      ${master_sites}
+livecheck.type     regex
+livecheck.regex    ${name}-(\\d+\\.\\d+\\.\\d+).tar.gz
Index: files/varnish-vcl-reload.in
===================================================================
--- files/varnish-vcl-reload.in	(revision 0)
+++ files/varnish-vcl-reload.in	(working copy)
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+cfg=${1:-@PREFIX@/etc/varnish/default.vcl}
+if [ ! -e "$cfg" ]; then
+    printf 'ERROR: VCL file %s does not exist\n' "$cfg" >&2
+    exit 1
+fi
+
+activecfg=$(varnishadm 'vcl.list' | awk '/active/ { print $3 }')
+if [ -z "$activecfg" ]; then
+    printf 'ERROR: No active VCL found!\n' >&2
+    exit 1
+fi
+
+newcfg=$(date +'vcl-%s')
+printf 'INFO: using new config %s\n' "$cfg"
+
+varnishadm "vcl.load $newcfg $cfg" &&
+varnishadm "vcl.use $newcfg" &&
+varnishadm "vcl.discard $activecfg"
Index: files/varnish.conf.in
===================================================================
--- files/varnish.conf.in	(revision 0)
+++ files/varnish.conf.in	(working copy)
@@ -0,0 +1,11 @@
+#
+# MANDATORIES command line options to varnishd
+#
+
+VARNISH_CFG="@PREFIX@/etc/varnish/default.vcl"
+
+VARNISHD_OPTS="-a 0.0.0.0:80
+               -f $VARNISH_CFG
+               -T localhost:6082
+               -s malloc,64M
+               -u nobody -g nobody"
Index: files/varnish.init.in
===================================================================
--- files/varnish.init.in	(revision 0)
+++ files/varnish.init.in	(working copy)
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+. @PREFIX@/etc/varnish/varnish.conf
+
+VARNISHD_PID="@PREFIX@/var/run/varnish/varnish.pid"
+
+if [[ -r $VARNISHD_PID ]]; then
+    read -r PID < "$VARNISHD_PID"
+    ps -p $PID &> /dev/null
+    CHECK=$?
+    if [[ "x$CHECK" == "x1" ]]; then
+      unset PID
+      rm -f "$VARNISHD_PID"
+    fi
+fi
+
+case $1 in
+    start)
+        @PREFIX@/sbin/varnishd $VARNISHD_OPTS -P $VARNISHD_PID
+    ;;
+    stop)
+        [[ $PID ]] && kill $PID &>/dev/null
+    ;;
+    restart)
+        $0 stop
+        sleep 1
+        $0 start
+    ;;
+    reload)
+        @PREFIX@/sbin/varnish-vcl-reload $VARNISH_CFG
+    ;;
+    *)
+        echo "usage: $0 {start|stop|restart|reload}"
+    ;;
+esac
