Ticket #39477: 0003-Add-scripts-to-make-the-administration-more-easer.patch

File 0003-Add-scripts-to-make-the-administration-more-easer.patch, 6.4 KB (added by robsonpeixoto@…, 11 years ago)
  • Portfile

    From bf0bb4e8e59fcc8f8b6d76b1d3f44014de99fb57 Mon Sep 17 00:00:00 2001
    From: Robson Peixoto <robsonpeixoto@gmail.com>
    Date: Wed, 19 Jun 2013 23:52:55 -0300
    Subject: [PATCH 4/4] Add scripts to make the administration more easer
    
     - Add reload vlc script from archlinux
     - Add varnish.conf file (make config easer)
     - Add init script (need to varnish.conf work)
    ---
     Portfile                    | 82 +++++++++++++++++++++++++++++++++++----------
     files/varnish-vcl-reload.in | 20 +++++++++++
     files/varnish.conf.in       | 11 ++++++
     files/varnish.init.in       | 35 +++++++++++++++++++
     4 files changed, 130 insertions(+), 18 deletions(-)
     create mode 100644 files/varnish-vcl-reload.in
     create mode 100644 files/varnish.conf.in
     create mode 100644 files/varnish.init.in
    
    diff --git a/Portfile b/Portfile
    index 49e3b1b..1e5a922 100644
    a b  
    11# -*- 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
    2 # $Id$
     2# $Id: Portfile 97982 2012-09-21 09:00:27Z ryandesign@macports.org $
    33
    4 PortSystem          1.0
     4PortSystem            1.0
    55
    6 name                varnish
    7 epoch               20110709
    8 version             3.0.4
    9 categories          www
    10 license             BSD zlib
    11 platforms           darwin
    12 maintainers         pmq openmaintainer
     6name                  varnish
     7epoch                 20110709
     8version               3.0.4
     9categories            www
     10platforms             darwin
     11maintainers           pmq openmaintainer
     12license               BSD
    1313
    14 description         Varnish is a state-of-the-art, high-performance HTTP accelerator
    15 long_description    Varnish was written from the ground up to be a high \
    16                     performance caching reverse proxy.
     14description           Varnish is a state-of-the-art, high-performance HTTP accelerator
     15long_description      Varnish was written from the ground up to be a high \
     16                      performance caching reverse proxy.
    1717
    18 homepage            http://www.varnish-cache.org
    19 master_sites        http://repo.varnish-cache.org/source/
     18homepage              http://www.varnish-cache.org
     19master_sites          http://repo.varnish-cache.org/source/
    2020
    21 checksums           rmd160  ed8aba21af17d5fee225eb03950fd90ad7b07911 \
    22                     sha256  4e044ccb5c76222bddf89c808f13ea8f66977972675aecb48a920f6800ad0f79
     21checksums             rmd160  ed8aba21af17d5fee225eb03950fd90ad7b07911 \
     22                      sha256  4e044ccb5c76222bddf89c808f13ea8f66977972675aecb48a920f6800ad0f79
    2323
    24 depends_build       port:pkgconfig
     24depends_build         port:pkgconfig \
     25                      port:py27-docutils
    2526
    26 depends_lib         port:pcre
     27depends_lib           port:pcre
     28
     29configure.args-append --with-rst2man=${prefix}/bin/rst2man-2.7.py
     30
     31startupitem.create    yes
     32startupitem.pidfile   auto "${prefix}/var/run/${name}/${name}.pid"
     33startupitem.start     "${prefix}/share/${name}/varnish.init start"
     34startupitem.stop      "${prefix}/share/${name}/varnish.init stop"
     35startupitem.restart   "${prefix}/share/${name}/varnish.init restart"
     36
     37post-destroot {
     38    # create dir
     39    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
     40
     41    # copy files
     42    xinstall -m 644 ${filespath}/varnish.conf.in ${destroot}${prefix}/etc/${name}/varnish.conf.default
     43    xinstall -m 755 ${filespath}/varnish.init.in ${destroot}${prefix}/share/${name}/${name}.init
     44    xinstall -m 755 ${filespath}/varnish-vcl-reload.in ${destroot}${prefix}/sbin/varnish-vcl-reload
     45
     46    # replace @PREFIX@ to ${prefix}
     47    reinplace "s|@PREFIX@|${prefix}|g" \
     48        ${destroot}${prefix}/etc/${name}/varnish.conf.default \
     49        ${destroot}${prefix}/share/${name}/${name}.init \
     50        ${destroot}${prefix}/sbin/varnish-vcl-reload
     51
     52    file rename ${destroot}${prefix}/etc/${name}/default.vcl ${destroot}${prefix}/etc/${name}/default.vcl.default
     53}
     54
     55post-activate {
     56    if {![file exists ${prefix}/etc/${name}/default.vcl]} {
     57        file copy ${prefix}/etc/${name}/default.vcl.default \
     58            ${prefix}/etc/${name}/default.vcl
     59    }
     60    if {![file exists ${prefix}/etc/${name}/varnish.conf]} {
     61        file copy ${prefix}/etc/${name}/varnish.conf.default \
     62            ${prefix}/etc/${name}/varnish.conf
     63    }
     64
     65    # dirs nedded to run varnish
     66    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/${name}
     67    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/run/${name}
     68}
     69
     70livecheck.url      ${master_sites}
     71livecheck.type     regex
     72livecheck.regex    ${name}-(\\d+\\.\\d+\\.\\d+).tar.gz
  • new file files/varnish-vcl-reload.in

    diff --git a/files/varnish-vcl-reload.in b/files/varnish-vcl-reload.in
    new file mode 100644
    index 0000000..f1a9988
    - +  
     1#!/bin/sh
     2
     3cfg=${1:-@PREFIX@/etc/varnish/default.vcl}
     4if [ ! -e "$cfg" ]; then
     5    printf 'ERROR: VCL file %s does not exist\n' "$cfg" >&2
     6    exit 1
     7fi
     8
     9activecfg=$(varnishadm 'vcl.list' | awk '/active/ { print $3 }')
     10if [ -z "$activecfg" ]; then
     11    printf 'ERROR: No active VCL found!\n' >&2
     12    exit 1
     13fi
     14
     15newcfg=$(date +'vcl-%s')
     16printf 'INFO: using new config %s\n' "$cfg"
     17
     18varnishadm "vcl.load $newcfg $cfg" &&
     19varnishadm "vcl.use $newcfg" &&
     20varnishadm "vcl.discard $activecfg"
  • new file files/varnish.conf.in

    diff --git a/files/varnish.conf.in b/files/varnish.conf.in
    new file mode 100644
    index 0000000..f4c2506
    - +  
     1#
     2# MANDATORIES command line options to varnishd
     3#
     4
     5VARNISH_CFG="@PREFIX@/etc/varnish/default.vcl"
     6
     7VARNISHD_OPTS="-a 0.0.0.0:80
     8               -f $VARNISH_CFG
     9               -T localhost:6082
     10               -s malloc,64M
     11               -u nobody -g nobody"
  • new file files/varnish.init.in

    diff --git a/files/varnish.init.in b/files/varnish.init.in
    new file mode 100644
    index 0000000..f5aa0a9
    - +  
     1#!/bin/bash
     2
     3. @PREFIX@/etc/varnish/varnish.conf
     4
     5VARNISHD_PID="@PREFIX@/var/run/varnish/varnish.pid"
     6
     7if [[ -r $VARNISHD_PID ]]; then
     8    read -r PID < "$VARNISHD_PID"
     9    ps -p $PID &> /dev/null
     10    CHECK=$?
     11    if [[ "x$CHECK" == "x1" ]]; then
     12      unset PID
     13      rm -f "$VARNISHD_PID"
     14    fi
     15fi
     16
     17case $1 in
     18    start)
     19        @PREFIX@/sbin/varnishd $VARNISHD_OPTS -P $VARNISHD_PID
     20    ;;
     21    stop)
     22        [[ $PID ]] && kill $PID &>/dev/null
     23    ;;
     24    restart)
     25        $0 stop
     26        sleep 1
     27        $0 start
     28    ;;
     29    reload)
     30        @PREFIX@/sbin/varnish-vcl-reload $VARNISH_CFG
     31    ;;
     32    *)
     33        echo "usage: $0 {start|stop|restart|reload}"
     34    ;;
     35esac