]> git.pld-linux.org Git - packages/varnish.git/blame - varnish.init
add VARNISHNCSA_OPTS config to add generic options to varnishncsa daemon
[packages/varnish.git] / varnish.init
CommitLineData
93f46ade 1#!/bin/sh
8e16c234
ER
2#
3# varnish Control the varnish HTTP accelerator
4#
b6d356f0 5# chkconfig: 345 90 10
8e16c234
ER
6# description: HTTP accelerator
7# processname: varnishd
8# config: /etc/varnish.conf
9# pidfile: /var/run/varnish/varnishd.pid
10
11# Source function library.
deec6cba
ER
12. /etc/rc.d/init.d/functions
13
14# Get network config
15. /etc/sysconfig/network
8e16c234 16
93f46ade 17# Get service config - may override defaults
deec6cba 18[ -f /etc/sysconfig/varnish ] && . /etc/sysconfig/varnish
8eb0a184 19
93f46ade
ER
20# Check that networking is up.
21if is_yes "${NETWORKING}"; then
22 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
23 msg_network_down "Varnish HTTP accelerator"
24 exit 1
25 fi
26else
27 exit 0
8eb0a184 28fi
8e16c234 29
51c06507 30PIDFILE=/var/run/varnishd.pid
c5703f6c 31
dc71b3cc
ER
32# import some env from parent process
33if [ -f /proc/$PPID/environ ]; then
94b672ed 34 eval $(tr '\0' '\n' < /proc/$PPID/environ | grep -E '^(USER|SUDO_USER|LOGNAME)=')
dc71b3cc
ER
35 LOGNAME=${SUDO_USER:-${LOGNAME:-$USER}}
36fi
37
34351593
ER
38# Generate a label, prefixed with the caller's username, from the
39# kernel random uuid generator, fallback to timestamp
40if [ -f /proc/sys/kernel/random/uuid ]; then
41 read uuid < /proc/sys/kernel/random/uuid
dc71b3cc 42 vcl_label="$(date +${LOGNAME}${LOGNAME:+:}%Y-%m-%d:%H.%M:${uuid})"
34351593 43else
dc71b3cc 44 vcl_label="$(date +${LOGNAME}${LOGNAME:+:}%s.%N)"
34351593
ER
45fi
46
1e36e413 47varnishadm() {
fa4f722e
ER
48 # default to "help" with no args
49 [ $# -eq 0 ] && set -- help
e3f01727 50 /usr/bin/varnishadm -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} ${VARNISH_SECRET_FILE:+-S ${VARNISH_SECRET_FILE}} "$@"
1e36e413 51}
e3f01727 52
34351593
ER
53# for simplier code
54vcl_load() {
1e36e413 55 varnishadm vcl.load "$@"
34351593
ER
56}
57vcl_use() {
1e36e413 58 varnishadm vcl.use "$@"
34351593
ER
59}
60vcl_discard() {
1e36e413 61 varnishadm vcl.discard "$@"
34351593
ER
62}
63
64# configtest itself
65# must return non-zero if check failed
66# output is discarded if checkconfig is ran without details
67configtest() {
68 local rc=0
a2fe8ee3 69
34351593 70 if [ -f /var/lock/subsys/varnish ]; then
68d07f3d 71 vcl_load $vcl_label ${VARNISH_VCL_CONF}; rc=$?
a2fe8ee3 72 # discard only if above succeeded
912165c4
ER
73 if [ $rc = 0 ]; then
74 vcl_discard $vcl_label || rc=$?
75 else
76 # this will display a bit more verbose error
77 /usr/sbin/varnishd -C -f ${VARNISH_VCL_CONF} >/dev/null
78 fi
79
34351593
ER
80 else
81 echo "Varnish is not running, config cannot be tested"
82 fi
83 return $rc
84}
85
86# wrapper for configtest
87checkconfig() {
88 local details=${1:-0}
89
90 if [ $details = 1 ]; then
91 # run config test and display report (status action)
92 show "Checking %s configuration" "Varnish HTTP accelerator"; busy
93 local out
94 out=$(configtest 2>&1)
95 RETVAL=$?
96 if [ $RETVAL = 0 ]; then
97 ok
98 else
99 fail
100 fi
101 [ "$out" ] && echo >&2 "$out"
102 else
103 # run config test and abort with nice message if failed
104 # (for actions checking status before action).
105 configtest >/dev/null 2>&1
106 RETVAL=$?
107 if [ $RETVAL != 0 ]; then
108 show "Checking %s configuration" "Varnish HTTP accelerator"; fail
109 nls 'Configuration test failed. See details with %s "checkconfig"' $0
110 exit $RETVAL
111 fi
112 fi
113}
114
fe3d4c4a 115start() {
deec6cba 116 if [ -f /var/lock/subsys/varnish ]; then
fe3d4c4a 117 msg_already_running "Varnish HTTP accelerator"
93f46ade 118 return
fe3d4c4a 119 fi
93f46ade 120
249b4976
ER
121 # default limits
122 SERVICE_LIMITS="${SERVICE_LIMIS:--n $NFILES -l $MEMLOCK}"
123
acd0b18b
ER
124 DAEMON_OPTS="
125 -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT}
126 -f ${VARNISH_VCL_CONF}
127 -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT}
128 -t ${VARNISH_TTL}
129 -u ${VARNISH_USER} -g ${VARNISH_GROUP}
130 -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT}
131 -n ${VARNISH_NAME}
c7e762f7 132 ${VARNISH_SECRET_FILE:+-S ${VARNISH_SECRET_FILE}}
acd0b18b 133 -s ${VARNISH_STORAGE}
c5703f6c 134 -P ${PIDFILE}
acd0b18b 135 "
249b4976 136
7212bcb2
ER
137 # iterate over $VARNISH_OPTS
138 for param in $VARNISH_PARAMS; do
139 DAEMON_OPTS="$DAEMON_OPTS -p $param"
140 done
141
93f46ade 142 msg_starting "Varnish HTTP accelerator"
9d3164e4 143 daemon /usr/sbin/varnishd $DAEMON_OPTS $VARNISH_OPTS
93f46ade 144 RETVAL=$?
deec6cba 145 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/varnish
fe3d4c4a 146}
8e16c234 147
fe3d4c4a 148stop() {
deec6cba 149 if [ ! -f /var/lock/subsys/varnish ]; then
fe3d4c4a 150 msg_not_running "Varnish HTTP accelerator"
93f46ade 151 return
fe3d4c4a 152 fi
93f46ade
ER
153
154 msg_stopping "Varnish HTTP accelerator"
c5703f6c 155 killproc --pidfile $PIDFILE /usr/sbin/varnishd
deec6cba 156 rm -f /var/lock/subsys/varnish
93f46ade
ER
157}
158
159condrestart() {
deec6cba 160 if [ ! -f /var/lock/subsys/varnish ]; then
93f46ade
ER
161 msg_not_running "Varnish HTTP accelerator"
162 RETVAL=$1
163 return
164 fi
165
166 stop
167 start
fe3d4c4a 168}
8e16c234 169
34351593
ER
170restart() {
171 if [ -f /var/lock/subsys/varnish ]; then
172 # checkconfig needs running varnish
173 checkconfig
174 fi
1e36e413 175 stop
34351593
ER
176 start
177}
178
179reload() {
180 if [ ! -f /var/lock/subsys/varnish ]; then
181 msg_not_running "Varnish HTTP accelerator"
182 RETVAL=7
183 return
184 fi
185
186 checkconfig
187 msg_reloading "Varnish HTTP accelerator"; busy
188 out=$(vcl_load $vcl_label ${VARNISH_VCL_CONF} && vcl_use $vcl_label 2>&1)
189 RETVAL=$?
190 if [ $RETVAL = 0 ]; then
191 ok
192 else
193 echo >&2 "$out"
194 fail
195 fi
196}
197
fe3d4c4a 198RETVAL=0
8e16c234
ER
199# See how we were called.
200case "$1" in
201 start)
fe3d4c4a 202 start
8e16c234
ER
203 ;;
204 stop)
fe3d4c4a 205 stop
8e16c234 206 ;;
93f46ade 207 restart)
34351593 208 restart
93f46ade
ER
209 ;;
210 try-restart)
211 condrestart 0
212 ;;
34351593
ER
213 reload|force-reload)
214 reload
215 ;;
216 checkconfig|configtest)
217 checkconfig 1
93f46ade 218 ;;
1e36e413
ER
219 varnishadm)
220 shift
221 varnishadm "$@"
222 ;;
8e16c234 223 status)
51c06507 224 status --pidfile $PIDFILE varnishd
8e16c234
ER
225 RETVAL=$?
226 ;;
8e16c234 227 *)
1e36e413 228 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|varnishadm|status}"
fe3d4c4a 229 exit 3
8e16c234
ER
230esac
231
232exit $RETVAL
This page took 1.089425 seconds and 4 git commands to generate.