aboutsummaryrefslogblamecommitdiffstats
path: root/main/varnish/varnishd.initd
blob: 54fb4a0a75c2b71ad00ff6350aa27a6a10cd6b23 (plain) (tree)
1
2
3
4
5
6
7



                                                                                                                  
 
                                         
                             






                                 

                                                       

                                                 



                                                                                  



                                                 



                                                                                    





                                 
                                                                       

               
                                               
                                                 
                                                                                  


                       

          










                                                                                  
                                                                                              








                                                                                   
 
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/www-servers/varnish/files/varnishd.initd,v 1.7 2009/08/30 06:28:07 hollow Exp $

VARNISH_CONF=${VARNISH_CONF:-${CFG_FILE}}
extra_commands="reload flush"

depend() {
	need net
}

start() {
	ebegin "Starting varnish"
        checkpath --directory --owner varnish:varnish \
	          --mode 755 ${VARNISHD_PID_FILE%/*}
	#allow varnishd to lock logfile to memory
	ulimit -l 82000
	start-stop-daemon --quiet --start \
	                  --pidfile ${VARNISHD_PID_FILE} \
			  --exec /usr/sbin/varnishd \
			  -- -P ${VARNISHD_PID_FILE} ${VARNISHD_OPTS} &> /dev/null
	eend $?

	if [ "${VARNISHNCSA_ARGS}" != "" ]; then
		ebegin "Starting varnish logging"
		start-stop-daemon --quiet --start \
				--pidfile ${VARNISHNCSA_PID_FILE} \
				--exec /usr/bin/varnishncsa \
				-- -D -P ${VARNISHNCSA_PID_FILE} ${VARNISHNCSA_ARGS}
		eend $?
	fi
}

stop() {
	ebegin "Stopping varnish"
	start-stop-daemon --quiet --stop --pidfile ${VARNISHD_PID_FILE}
	eend $?

	if [ -e ${VARNISHNCSA_PID_FILE} ]; then
		ebegin "Stopping varnish logging"
		start-stop-daemon --quiet --stop --pidfile ${VARNISHNCSA_PID_FILE}
		eend $?
	fi
}

reload() {
	ebegin "Reloading varnish"

	# purge unused old configurations
	DISCARDS=$(/usr/bin/varnishadm -T $ADMINHOSTPORT vcl.list |
		sed -ne "s/^available *0 *\(reload.*\)/ \\1/p")
	for VCL in $DISCARDS ; do
		/usr/bin/varnishadm -T $ADMINHOSTPORT vcl.discard $VCL > /dev/null
	done

	# reload new one
	NOW=$(date +%Y%m%d-%H%M%S-%s)
	/usr/bin/varnishadm -T $ADMINHOSTPORT vcl.load reload-$NOW ${VARNISH_CONF} > /dev/null
	/usr/bin/varnishadm -T $ADMINHOSTPORT vcl.use  reload-$NOW > /dev/null

	eend $?
}

flush() {
	ebegin "Flushing varnish cache"
	/usr/bin/varnishadm -T $ADMINHOSTPORT ban obj.http.host "~" "." > /dev/null
	eend $?
}