[Varnish] #523: How to stop varnish ?

Varnish varnish-bugs at projects.linpro.no
Tue Jun 23 22:10:11 CEST 2009


#523: How to stop varnish ?
--------------------+-------------------------------------------------------
 Reporter:  ovi1    |        Owner:       
     Type:  defect  |       Status:  new  
 Priority:  normal  |    Milestone:       
Component:  build   |      Version:  trunk
 Severity:  normal  |   Resolution:       
 Keywords:          |  
--------------------+-------------------------------------------------------
Comment (by kb):

 "varnishadm stop" will stop the child, but not the parent.  I'm not aware
 of an alternative for killing the parent other than 'kill'.

 This is what I use right now, until "varnishadm die" or somesuch is
 implemented (requires "varnishd -P /foobar/varnishd.pid").  Unless we're
 both missing something?

 {{{
 #!/bin/bash
 export PATH=/usr/sbin:/usr/bin:/sbin:/bin
 LISTEN_PORT=3333
 MGMT_PORT=2222
 PID_FILE=/foobar/varnishd.pid

 echo -n "Gracefully stopping varnishd..."
 /usr/local/bin/varnishadm -T :${MGMT_PORT} stop > /dev/null

 if [ -f $PID_FILE ]; then
         kill `cat ${PID_FILE}`
         rm -f $PID_FILE
 fi

 c=30
 stat=0
 while [ $stat -eq 0 -a $c -gt 0 ]; do
         PIDS=`ps -ef | egrep "varnishd.*:${LISTEN_PORT}" | grep -v grep |
 awk '{print $2}'`
         if [ "${PIDS}" == '' ]; then
                 stat=1
         else
                 echo -n '.'
                 if [ $c -gt 2 ]; then
                         kill $PIDS
                 else
                         kill -9 $PIDS
                 fi
                 sleep 1
                 let c--
         fi
 done

 if [ $stat -eq 0 ]; then
         echo 'FAILED!'
         exit -1
 fi

 echo 'Done.'
 exit 0
 }}}

-- 
Ticket URL: <http://varnish.projects.linpro.no/ticket/523#comment:1>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator


More information about the varnish-bugs mailing list