Ticket #35863: 20130104-varnish-startup.patch​

File 20130104-varnish-startup.patch​, 4.1 KB (added by robsonpeixoto@…, 12 years ago)

With 4 spaces and without convert tab to space

Line 
1Index: Portfile
2===================================================================
3--- Portfile    (revision 100882)
4+++ Portfile    (working copy)
5@@ -5,6 +5,7 @@
6 name                 varnish
7 epoch                 20110709
8 version               3.0.3
9+revision              1
10 categories           www
11 platforms            darwin
12 maintainers          pmq openmaintainer
13@@ -22,3 +23,44 @@
14 depends_build         port:pkgconfig
15 
16 depends_lib           port:pcre
17+
18+startupitem.create    yes
19+startupitem.start     "${prefix}/share/${name}/varnish.init start"
20+startupitem.stop      "${prefix}/share/${name}/varnish.init stop"
21+
22+post-destroot {
23+    # create dir
24+    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
25+
26+    # copy files
27+    xinstall -m 644 ${filespath}/varnish.conf.in ${destroot}${prefix}/etc/${name}/varnish.conf.default
28+    xinstall -m 755 ${filespath}/varnish.init.in ${destroot}${prefix}/share/${name}/${name}.init
29+    xinstall -m 755 ${filespath}/varnish-vcl-reload.in ${destroot}${prefix}/sbin/varnish-vcl-reload
30+
31+    # replace @PREFIX@ to ${prefix}
32+    reinplace "s|@PREFIX@|${prefix}|g" \
33+        ${destroot}${prefix}/etc/${name}/varnish.conf.default \
34+        ${destroot}${prefix}/share/${name}/${name}.init \
35+        ${destroot}${prefix}/sbin/varnish-vcl-reload
36+
37+    file rename ${destroot}${prefix}/etc/${name}/default.vcl ${destroot}${prefix}/etc/${name}/default.vcl.default
38+}
39+
40+post-activate {
41+    if {![file exists ${prefix}/etc/${name}/default.vcl]} {
42+        file copy ${prefix}/etc/${name}/default.vcl.default \
43+            ${prefix}/etc/${name}/default.vcl
44+    }
45+    if {![file exists ${prefix}/etc/${name}/varnish.conf]} {
46+        file copy ${prefix}/etc/${name}/varnish.conf.default \
47+            ${prefix}/etc/${name}/varnish.conf
48+    }
49+
50+    # dirs nedded to run varnish
51+    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/${name}
52+    xinstall -d -m 755 -o nobody -g nobody ${prefix}/var/run/${name}
53+}
54+
55+livecheck.url      ${master_sites}
56+livecheck.type     regex
57+livecheck.regex    ${name}-(\\d+\\.\\d+\\.\\d+).tar.gz
58\ No newline at end of file
59Index: files/varnish-vcl-reload.in
60===================================================================
61--- files/varnish-vcl-reload.in (revision 0)
62+++ files/varnish-vcl-reload.in (working copy)
63@@ -0,0 +1,20 @@
64+#!/bin/sh
65+
66+cfg=${1:-@PREFIX@/etc/varnish/default.vcl}
67+if [ ! -e "$cfg" ]; then
68+    printf 'ERROR: VCL file %s does not exist\n' "$cfg" >&2
69+    exit 1
70+fi
71+
72+activecfg=$(varnishadm 'vcl.list' | awk '/active/ { print $3 }')
73+if [ -z "$activecfg" ]; then
74+    printf 'ERROR: No active VCL found!\n' >&2
75+    exit 1
76+fi
77+
78+newcfg=$(date +'vcl-%s')
79+printf 'INFO: using new config %s\n' "$cfg"
80+
81+varnishadm "vcl.load $newcfg $cfg" &&
82+varnishadm "vcl.use $newcfg" &&
83+varnishadm "vcl.discard $activecfg"
84Index: files/varnish.conf.in
85===================================================================
86--- files/varnish.conf.in       (revision 0)
87+++ files/varnish.conf.in       (working copy)
88@@ -0,0 +1,13 @@
89+#
90+# MANDATORIES command line options to varnishd
91+#
92+
93+VARNISH_CFG="@PREFIX@/etc/varnish/default.vcl"
94+VARNISHD_PID="@PREFIX@/var/run/varnish/varnish.pid"
95+
96+VARNISHD_OPTS="-a 0.0.0.0:80 \
97+               -f $VARNISH_CFG \
98+               -T localhost:6082 \
99+               -P $VARNISHD_PID \
100+               -s malloc,64M
101+               -u nobody -g nobody"
102Index: files/varnish.init.in
103===================================================================
104--- files/varnish.init.in       (revision 0)
105+++ files/varnish.init.in       (working copy)
106@@ -0,0 +1,33 @@
107+#!/bin/bash
108+
109+. @PREFIX@/etc/varnish/varnish.conf
110+
111+if [[ -r $VARNISHD_PID ]]; then
112+    read -r PID < "$VARNISHD_PID"
113+    ps -p $PID &> /dev/null
114+    CHECK=$?
115+    if [[ "x$CHECK" == "x1" ]]; then
116+      unset PID
117+      rm -f "$VARNISHD_PID"
118+    fi
119+fi
120+
121+case $1 in
122+    start)
123+        @PREFIX@/sbin/varnishd $VARNISHD_OPTS
124+    ;;
125+    stop)
126+        [[ $PID ]] && kill $PID &>/dev/null
127+    ;;
128+    restart)
129+        $0 stop
130+        sleep 1
131+        $0 start
132+    ;;
133+    reload)
134+        @PREFIX@/sbin/varnish-vcl-reload $VARNISH_CFG
135+    ;;
136+    *)
137+        echo "usage: $0 {start|stop|restart|reload}"
138+    ;;
139+esac