4月 282010
昨日プロセスを強引にとる手法でやったところ
もっといい方法があるよと@mikedaさんが教えてくれましたので修正しました
自前で作るRPMのvarnishのinit.dはこれでいこうかなーと
/etc/init.d/varnish
#! /bin/sh # # varnish Control the varnish HTTP accelerator # # chkconfig: - 90 10 # description: Varnish is a high-perfomance HTTP accelerator # processname: varnishd # config: /etc/sysconfig/varnish # pidfile: /var/run/varnish/varnishd.pid ### BEGIN INIT INFO # Provides: varnish # Required-Start: $network $local_fs $remote_fs # Required-Stop: $network $local_fs $remote_fs # Should-Start: $syslog # Short-Description: start and stop varnishd # Description: Varnish is a high-perfomance HTTP accelerator ### END INIT INFO # Source function library. . /etc/init.d/functions retval=0 pidfile=/var/run/varnish.pid exec="/usr/sbin/varnishd" prog="varnishd" config="/etc/sysconfig/varnish" lockfile="/var/lock/subsys/varnish" # Include varnish defaults [ -e /etc/sysconfig/varnish ] && . /etc/sysconfig/varnish ################################ PID=`cat /var/run/varnish.pid` ADM=`cat /proc/$PID/cmdline|tr '\0' '!'|sed -e "s/^.*-T\!\([^\!]\\+\)\!.*$/\\1/g"` NOW=`date +%s` if [ -z $VARNISH_VCL_CONF ]; then VARNISH_VCL_CONF=`cat /proc/$PID/cmdline|tr '\0' '!'|sed -e "s/^.*-f\!\([^\!]\\+\)\!.*$/\\1/g"` fi ################################ start() { if [ ! -x $exec ] then echo $exec not found exit 5 fi if [ ! -f $config ] then echo $config not found exit 6 fi echo -n "Starting varnish HTTP accelerator: " # Open files (usually 1024, which is way too small for varnish) ulimit -n ${NFILES:-131072} # Varnish wants to lock shared memory log in memory. ulimit -l ${MEMLOCK:-82000} # $DAEMON_OPTS is set in /etc/sysconfig/varnish. At least, one # has to set up a backend, or /tmp will be used, which is a bad idea. if [ "$DAEMON_OPTS" = "" ]; then echo "\$DAEMON_OPTS empty." echo -n "Please put configuration options in $config" return 6 else # Varnish always gives output on STDOUT daemon $exec -P $pidfile "$DAEMON_OPTS" > /dev/null 2>&1 retval=$? if [ $retval -eq 0 ] then touch $lockfile echo_success echo else echo_failure fi return $retval fi } stop() { echo -n "Stopping varnish HTTP accelerator: " killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } graceful() { echo reload VCL file: $VARNISH_VCL_CONF varnishadm -T $ADM vcl.load reload$NOW $VARNISH_VCL_CONF || error varnishadm -T $ADM vcl.use reload$NOW || error echo Current configs: echo_success echo varnishadm -T $ADM vcl.list } error(){ echo_failure echo exit 1 } restart() { stop start } reload() { graceful } force_reload() { restart } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } # See how we were called. case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; graceful) $1 ;; reload) $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|graceful|force-reload}" exit 2 esac exit $?
sysconfigでVCLファイルの定義がされている場合はそれを優先して読み込むように修正しました(VARNISH_VCL_CONF)
またプロセスの引数はPIDファイルで特定したプロセスから取得することでよりスマートに!
[…] This post was mentioned on Twitter by \いわなちゃん/. \いわなちゃん/ said: [blog] Varnishを再起動無しで設定を適用する方法(修正版) http://is.gd/bLhda […]
あっ最初のstart時にファイルがないとかでるのでそのうち修正します(ちゃんと動くけど気持ち悪いよね!
wikiに情報移動してます
http://wiki.xcir.net/index.php?title=Varnish%E3%81%AEinit%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E6%94%B9%E9%80%A0(graceful%E5%AF%BE%E5%BF%9C)