Ticket #35863: startupitem_livecheck.patch

File startupitem_livecheck.patch, 4.7 KB (added by robsonpeixoto@…, 12 years ago)

Add statupitem, livecheck and a reload vcl script

  • Portfile

     
    55name                  varnish
    66epoch                 20110709
    77version               3.0.3
     8revision              1
    89categories            www
    910platforms             darwin
    1011maintainers           pmq openmaintainer
     
    2223depends_build         port:pkgconfig
    2324
    2425depends_lib           port:pcre
     26
     27startupitem.create      yes
     28startupitem.start               "${prefix}/sbin/varnish-server start"
     29startupitem.stop                "${prefix}/sbin/varnish-server stop"
     30startupitem.restart             "${prefix}/sbin/varnish-server restart"
     31
     32post-build {
     33        copy ${filespath}/varnish-server.in ${workpath}/varnish-server
     34        copy ${filespath}/varnish-vcl-reload.in ${workpath}/varnish-vcl-reload
     35        copy ${filespath}/varnish-server.conf.in ${workpath}/varnish-server.conf.default       
     36       
     37    reinplace "s|@PREFIX@|${prefix}|g" \
     38        ${workpath}/varnish-server \
     39        ${workpath}/varnish-vcl-reload \
     40                ${workpath}/varnish-server.conf.default
     41}
     42
     43post-destroot {
     44        move ${destroot}${prefix}/etc/varnish/default.vcl ${destroot}${prefix}/etc/varnish/default.vcl.default
     45       
     46        xinstall -m 755 ${workpath}/varnish-server ${destroot}${prefix}/sbin/varnish-server
     47        xinstall -m 755 ${workpath}/varnish-vcl-reload ${destroot}${prefix}/bin/varnish-vcl-reload
     48        xinstall -m 644 ${workpath}/varnish-server.conf.default ${destroot}${prefix}/etc/varnish/varnish-server.conf.default
     49}
     50
     51post-activate {
     52    if {![file exists ${prefix}/etc/varnish/varnish-server.conf]} {
     53        file copy ${prefix}/etc/varnish/varnish-server.conf.default \
     54            ${prefix}/etc/varnish/varnish-server.conf
     55    }
     56    if {![file exists ${prefix}/etc/varnish/default.vcl]} {
     57        file copy ${prefix}/etc/varnish/default.vcl.default \
     58            ${prefix}/etc/varnish/default.vcl
     59    }
     60    xinstall -m 755 -d ${prefix}/var/varnish/
     61}
     62
     63livecheck.url                   ${master_sites}
     64livecheck.type                  regex
     65livecheck.regex                 varnish-(\\d+\\.\\d+\\.\\d+).tar.gz
  • files/varnish-server.conf.in

     
     1# Command line options to varnishd
     2# based on https://projects.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/varnish
     3
     4VARNISH_CFG="@PREFIX@/etc/varnish/default.vcl"
     5
     6VARNISH_PID="@PREFIX@/var/run/varnishd.pid"
     7
     8VARNISHD_OPTS="-a 0.0.0.0:80 \
     9                           -f $VARNISH_CFG \
     10                           -T localhost:6082 \
     11                           -P $VARNISH_PID \
     12                           -s malloc,64M \
     13                           -u nobody -g nobody"
  • files/varnish-server.in

     
     1#!/bin/bash
     2
     3. @PREFIX@/etc/varnish/varnish-server.conf
     4
     5pidfile=$VARNISH_PID
     6if [[ -r $pidfile ]]; then
     7  read -r PID < "$pidfile"
     8  ps -p $PID 2&> /dev/null
     9  if [[ $? != 0 ]]; then
     10    # stale pidfile
     11    unset PID
     12    rm -f "$pidfile"
     13  fi
     14fi
     15
     16case $1 in
     17  start)
     18    if /opt/local/sbin/varnishd $VARNISHD_OPTS; then
     19    exit 0
     20    else
     21      echo "Varnish start FAIL"
     22      exit 1
     23    fi
     24    ;;
     25  stop)
     26    if [[ $PID ]] && kill $PID &>/dev/null; then
     27      exit 0
     28    else
     29      exit 1
     30    fi
     31    ;;
     32  restart)
     33    $0 stop
     34    sleep 1
     35    $0 start
     36    ;;
     37  reload)
     38    status "Recompiling and Reloading VCL" varnish-vcl-reload $VARNISH_CFG
     39    ;;
     40  *)
     41    echo "usage: $0 {start|stop|restart|reload}"
     42  ;;
     43esac
  • files/varnish-vcl-reload.in

    Property changes on: files/varnish-server.in
    ___________________________________________________________________
    Added: svn:executable
    ## -0,0 +1 ##
    +*
    \ No newline at end of property
     
     1#!/bin/sh
     2# based on https://projects.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/varnish
     3
     4cfg=${1:-@PREFIX@/etc/varnish/default.vcl}
     5if [ ! -e "$cfg" ]; then
     6  printf 'ERROR: VCL file %s does not exist\n' "$cfg" >&2
     7  exit 1
     8fi
     9
     10activecfg=$(varnishadm 'vcl.list' | awk '/active/ { print $3 }')
     11if [ -z "$activecfg" ]; then
     12  printf 'ERROR: No active VCL found!\n' >&2
     13  exit 1
     14fi
     15
     16newcfg=$(date +'vcl-%s')
     17printf 'INFO: using new config %s\n' "$cfg"
     18
     19varnishadm "vcl.load $newcfg $cfg" &&
     20varnishadm "vcl.use $newcfg" &&
     21varnishadm "vcl.discard $activecfg"