blob: b6354687f7fcc1f05ceac72f1e37e8acd3a8eca8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/bin/sh
# varnish rc script
# written by Matt Schurenko <matt.schurenko@gmail.com>
USAGE="usage: $0 start|stop|restart"
BIN='/usr/sbin/varnishd'
CONF='/etc/varnish/default.vcl'
PID='/var/run/varnish.pid'
##
# adjust the following variables accordingly
##
BACKING_FILE='/var/lib/varnish-cache'
ADMIN_IP='127.0.0.1'
ADMIN_PORT=8001
HTTP_IP='0.0.0.0'
HTTP_PORT=80
CACHE_SIZE='1g'
# ttl assigned to objects without ttl values (default 120s)
DEFAULT_TTL=604800 # 7 days
FILE_DESCRIPTORS=131072
MIN_THREADS=5
MAX_THREADS=500
THREAD_TIMEOUT=300
# maximum number of http headers (default is 64)
HTTP_HEADERS=384
# connection timout for backend (default is 0.4s)
CONNECT_TIMEOUT='4.0'
VARNISH_OPTS="-f $CONF \
-s file,${BACKING_FILE},$CACHE_SIZE \
-T $ADMIN_IP:${ADMIN_PORT} \
-a $HTTP_IP:${HTTP_PORT} \
-t $DEFAULT_TTL \
-w${MIN_THREADS},${MAX_THREADS},${THREAD_TIMEOUT} \
-P $PID"
VARNISH_PARAMS="-p http_headers=$HTTP_HEADERS \
-p connect_timeout=$CONNECT_TIMEOUT"
varnish_start() {
if [ -e $PID ];then
if [ `pgrep varnishd|head -n1` == `cat $PID` ];then
echo "varnish is already running"
exit 1
else # pid file must be stale
"$PID exists but pid doesn't match pid of varnishd. please investigate."
exit 2
fi
fi
ulimit -n $FILE_DESCRIPTORS
echo "starting varnish..."
$BIN $VARNISH_OPTS $VARNISH_PARAMS
}
varnish_stop() {
echo "stopping varnish..."
killall `echo $BIN | awk -F'/' '{print $NF}'`
if [ -e $PID ];then
rm $PID
fi
}
case "$1" in
start)
varnish_start
;;
stop)
varnish_stop
;;
restart)
varnish_stop
sleep 1
varnish_start
;;
*) echo -e $USAGE
;;
esac
|