#!/bin/bash # # chkconfig: 345 99 8 # cache: Starts Varnish Cache Service # description: Varnish Reverse Cache for Web Sites # process name: cache # Source function library. . /etc/init.d/functions # Configurado por Felipe Ferreira @ 5/01/10 #Edit here to your .vcl FILE SITEID=intra RETVAL=0 getpid() { pid=`ps -ef | grep 'varnishd -a :80 -T localhost:23 -n intra' | grep -v grep | awk 'NR == 1 { max = $2; maxline = $0; next; } $2 < max { max=$2; maxline=$0 }; END { print max }'` # Should get only ONE } start() { echo -n $"Starting Varnish Cache Daemon: " getpid if [ -z "$pid" ]; then # in case of unclean shutdown nohup /bin/su root -c "/usr/local/sbin/varnishd -a :80 -T localhost:23 -n $SITEID -P /var/run/$SITEID.pid -u varnish -f /usr/local/etc/varnish/$SITEID.vcl -s file,/var/cache/varnish" RETVAL=$? fi if [ $RETVAL -eq 0 ]; then echo_success else echo_failure fi echo return $RETVAL } stop() { echo -n $"Stoping Varnish Cache ID: $SITEID: " getpid RETVAL=$? if [ -n "$pid" ]; then kill $pid sleep 6 getpid if [ -z "$pid" ]; then rm -f /var/run/$SITEID echo_success else echo_failure fi else echo_failure fi echo return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) getpid # echo $pid if [ -n "$pid" ]; then echo "Varnish Daemon $SITEID (pid $pid) is running..." else RETVAL=1 echo "Varnish $SITEID is stopped" fi ;; stats) varnishadm -T localhost:23 stats |more ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|status|stats|restart}" exit 1 ;; esac exit $RETVAL