From owner-svn-ports-head@freebsd.org Tue Nov 3 15:08:48 2015 Return-Path: Delivered-To: svn-ports-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA71FA25C68; Tue, 3 Nov 2015 15:08:48 +0000 (UTC) (envelope-from feld@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 667AA1C21; Tue, 3 Nov 2015 15:08:48 +0000 (UTC) (envelope-from feld@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA3F8l5o072648; Tue, 3 Nov 2015 15:08:47 GMT (envelope-from feld@FreeBSD.org) Received: (from feld@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA3F8l8i072643; Tue, 3 Nov 2015 15:08:47 GMT (envelope-from feld@FreeBSD.org) Message-Id: <201511031508.tA3F8l8i072643@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: feld set sender to feld@FreeBSD.org using -f From: Mark Felder Date: Tue, 3 Nov 2015 15:08:47 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r400701 - in head/www/varnish4: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2015 15:08:48 -0000 Author: feld Date: Tue Nov 3 15:08:46 2015 New Revision: 400701 URL: https://svnweb.freebsd.org/changeset/ports/400701 Log: www/varnish4: Fix race condition on start varnishlog and varnishncsa had a race condition with varnishd on startup as they will notice varnishd's leftover _.vsm file and try to connect to varnishd but occasionally fail due to varnishd not being fully operational yet. By adding "-t off" flag as default to varnishncsa and varnishlog they will wait indefinitely for varnishd to start up instead of just exiting. Other bugs fixed: * varnishncsa_logformat in rc.conf mostly works Unfortunately due to shell expansion we still cannot pass quotes (") so if you need those in your log format you will have to manage varnishncsa startup yourself. I apologize, but there's not much we can do at the moment. I'm working with upstream to allow loading configuration from a file. Note that Debian has complained too... * Default permissions for log and pidfiles have been corrected They are now correctly set to 664 for pidfiles and 644 for log files * Description of default flags for varnishncsa and varnishlog have been adjusted to reflect reality New features: * We now support "checkconfig" and "reload" options like on RedHat distributions You can do "service varnishd checkconfig" to validate your vcl is functional. Doing a "service varnishd reload" also works without interrupting service and creates a new vcl reflecting the date+timestamp. Varnishd now does a checkconfig before starting and will also prevent you from breaking a running instance by doing a "restart" with an invalid vcl. Thanks to many for the reports and testing. Differential Revision: https://reviews.freebsd.org/D4016 Modified: head/www/varnish4/Makefile head/www/varnish4/files/varnishd.in head/www/varnish4/files/varnishlog.in head/www/varnish4/files/varnishncsa.in Modified: head/www/varnish4/Makefile ============================================================================== --- head/www/varnish4/Makefile Tue Nov 3 13:27:11 2015 (r400700) +++ head/www/varnish4/Makefile Tue Nov 3 15:08:46 2015 (r400701) @@ -2,7 +2,7 @@ PORTNAME= varnish PORTVERSION= 4.1.0 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= www MASTER_SITES= http://repo.varnish-cache.org/source/ PKGNAMESUFFIX= 4 Modified: head/www/varnish4/files/varnishd.in ============================================================================== --- head/www/varnish4/files/varnishd.in Tue Nov 3 13:27:11 2015 (r400700) +++ head/www/varnish4/files/varnishd.in Tue Nov 3 15:08:46 2015 (r400701) @@ -65,6 +65,11 @@ load_rc_config ${name} command="%%PREFIX%%/sbin/${name}" pidfile="${varnishd_pidfile}" +configtest_cmd="varnishd_checkconfig" +reload_cmd="varnishd_reload" +restart_precmd="varnishd_checkconfig" +start_precmd="varnishd_precmd" +extra_commands="status reload configtest" if [ -n "${varnishd_config}" ] ; then : ${varnishd_flags:="-j unix,user=${varnishd_jailuser} -P ${varnishd_pidfile} -a ${varnishd_listen} -T ${varnishd_admin} -f ${varnishd_config} -s ${varnishd_storage} -h ${varnishd_hash} ${varnishd_extra_flags}"} @@ -72,4 +77,52 @@ else : ${varnishd_flags:="-j unix,user=${varnishd_jailuser} -P ${varnishd_pidfile} -a ${varnishd_listen} -T ${varnishd_admin} -b ${varnishd_backend} -s ${varnishd_storage} -h ${varnishd_hash} ${varnishd_extra_flags}"} fi +varnishd_checkconfig() +{ + if [ -z "${varnishd_config}" ]; then + echo "${name}: nothing to check, no configuration file defined, builtin VCL used" + else + echo "Performing sanity check on ${name} configuration:" + if eval ${command} -C -f "${varnishd_config}" 2> /dev/null ; then + echo "${name}: the configuration file ${varnishd_config} syntax is ok" + else + err 1 "${name}: the configuration file ${varnishd_config} syntax is NOT ok" + fi + fi +} + +# Adapted from work done by Ingvar Hagelund (see redhat/varnish_reload_vcl) +varnishd_reload() +{ + local _current_config_name _new_config_name _varnishadm_cmd + + if [ -z "${varnishd_config}" ]; then + echo "${name}: nothing to reload, no configuration file defined, builtin VCL used" + else + _new_config_name="rc.d_reloaded@$(date +%Y%m%d%H%M%S)" + _varnishadm_cmd="%%PREFIX%%/bin/varnishadm ${varnish_cli_flags}" + if ! eval ${_varnishadm_cmd} vcl.list > /dev/null; then + err 1 "${name}: can't connect to varnishadm" + fi + _current_config_name=$(${_varnishadm_cmd} vcl.list | awk ' /^active/ { print $3 } ') + if ! eval ${_varnishadm_cmd} vcl.load ${_new_config_name} ${varnishd_config} > /dev/null; then + err 1 "${name}: vcl.load failed, you're still using previous rules (${_current_config_name})" + fi + if eval ${_varnishadm_cmd} vcl.use ${_new_config_name} > /dev/null; then + echo "VCL file \"${varnishd_config}\" has been successfully loaded as \"${_new_config_name}\"" + echo "To remove previous loaded configurations, you should run \"${_varnishadm_cmd} vcl.discard \" by yourself" + else + err 1 "${name}: vcl.use failed, you're still using previous rules (${_current_config_name})" + fi + fi + + return 0 +} + +varnishd_precmd() +{ + # Check config before starting + varnishd_checkconfig +} + run_rc_command "$1" Modified: head/www/varnish4/files/varnishlog.in ============================================================================== --- head/www/varnish4/files/varnishlog.in Tue Nov 3 13:27:11 2015 (r400700) +++ head/www/varnish4/files/varnishlog.in Tue Nov 3 15:08:46 2015 (r400701) @@ -21,12 +21,12 @@ # default: "/var/log/varnish.log" # # varnishlog_flags - command line arguments. -# default: "-D -P ${varnishlog_pidfile} -a -w ${varnishlog_file}" +# default: "-t off -P ${varnishlog_pidfile} -D -a -A -w ${varnishlog_file}" # # Add the following line to /etc/newsyslog.conf to rotate the log file # once a day: # -# /var/log/varnish.log 640 7 * @T00 JB /var/run/varnishlog.pid +# /var/log/varnish.log varnishlog:varnish 640 7 * @T00 JB /var/run/varnishlog.pid # # See varnishlog(1) for a detailed overview of command-line options. # @@ -40,43 +40,26 @@ load_rc_config ${name} : ${varnishlog_enable:=NO} : ${varnishlog_pidfile=/var/run/${name}.pid} : ${varnishlog_file=/var/log/varnish.log} -: ${varnishlog_flags="-P ${varnishlog_pidfile} -D -a -A -w ${varnishlog_file}"} -: ${varnishlog_user=varnishlog} +: ${varnishlog_flags="-t off -P ${varnishlog_pidfile} -D -a -A -w ${varnishlog_file}"} -command="%%PREFIX%%/bin/${name}" +procname="%%PREFIX%%/bin/${name}" +command="/usr/sbin/daemon" +command_args="-f -u varnishlog ${procname} ${varnishlog_flags}" pidfile=${varnishlog_pidfile} start_precmd=precmd precmd() { + # varnishlog_flags gets applied too early if we don't do this. + rc_flags="" + if [ ! -e ${pidfile} ]; then - install -o ${varnishlog_user} -g varnish /dev/null ${pidfile}; + install -o varnishlog -g varnish -m 644 /dev/null ${pidfile}; fi if [ ! -e ${varnishlog_file} ]; then - install -o ${varnishlog_user} -g varnish /dev/null ${varnishlog_file}; + install -o varnishlog -g varnish -m 640 /dev/null ${varnishlog_file}; fi - - waitcount=0 - vsm=%%PREFIX%%/varnish/$(hostname)/_.vsm - - # wait no longer than 5s for _.vsm file to arrive from varnishd - while : - do - if [ -f ${vsm} ] ; then - break - else - case "${waitcount}" in - 5) echo "${name}: Failed to start. Missing ${vsm} ?" - break - ;; - *) echo "${name}: waiting for ${vsm}" - waitcount=$((waitcount+1)) - sleep 1 - ;; - esac - fi - done } run_rc_command "$1" Modified: head/www/varnish4/files/varnishncsa.in ============================================================================== --- head/www/varnish4/files/varnishncsa.in Tue Nov 3 13:27:11 2015 (r400700) +++ head/www/varnish4/files/varnishncsa.in Tue Nov 3 15:08:46 2015 (r400701) @@ -21,7 +21,7 @@ # default: "/var/log/varnishncsa.log" # # varnishncsa_flags - command line arguments. -# default: "-D -P ${varnishncsa_pidfile} -a -w ${varnishncsa_file}${varnishncsa_logformat:+ -P \"$varnishncsa_logformat\"" +# default: "-t off -P ${varnishncsa_pidfile} -D -a -w ${varnishncsa_file}${varnishncsa_logformat:+ -F \"$varnishncsa_logformat\"}" # # varnishncsa_logformat - log file format. # default: "" (uses varnishncsa's default format) @@ -30,7 +30,7 @@ # Add the following line to /etc/newsyslog.conf to rotate the log file # once a day: # -# /var/log/varnishncsa.log 640 7 * @T00 JB /var/run/varnishncsa.pid +# /var/log/varnishncsa.log varnishlog:varnish 640 7 * @T00 JB /var/run/varnishncsa.pid # # See varnishncsa(1) for a detailed overview of command-line options. # @@ -45,43 +45,26 @@ load_rc_config ${name} : ${varnishncsa_enable:=NO} : ${varnishncsa_pidfile=/var/run/${name}.pid} : ${varnishncsa_file=/var/log/${name}.log} -: ${varnishncsa_flags="-P ${varnishncsa_pidfile} -D -a -w ${varnishncsa_file}${varnishncsa_logformat:+ -F \"$varnishncsa_logformat\"}"} -: ${varnishncsa_user=varnishlog} +: ${varnishncsa_flags="-t off -P ${varnishncsa_pidfile} -D -a -w ${varnishncsa_file} ${varnishncsa_logformat:+-F \"$varnishncsa_logformat\"}"} -command="%%PREFIX%%/bin/${name}" +procname="%%PREFIX%%/bin/${name}" +command="/usr/sbin/daemon" +command_args="-f -u varnishlog ${procname} ${varnishncsa_flags}" pidfile=${varnishncsa_pidfile} start_precmd=precmd precmd() { + # $varnishncsa_flags gets applied too early if we don't do this. + rc_flags="" + if [ ! -e ${pidfile} ]; then - install -o ${varnishncsa_user} -g varnish /dev/null ${pidfile}; + install -o varnishlog -g varnish -m 644 /dev/null ${pidfile}; fi if [ ! -e ${varnishncsa_file} ]; then - install -o ${varnishncsa_user} -g varnish /dev/null ${varnishncsa_file}; + install -o varnishlog -g varnish -m 640 /dev/null ${varnishncsa_file}; fi - - waitcount=0 - vsm=%%PREFIX%%/varnish/$(hostname)/_.vsm - - # wait no longer than 5s for _.vsm file to arrive from varnishd - while : - do - if [ -f ${vsm} ] ; then - break - else - case "${waitcount}" in - 5) echo "${name}: Failed to start. Missing ${vsm} ?" - break - ;; - *) echo "${name}: waiting for ${vsm}" - waitcount=$((waitcount+1)) - sleep 1 - ;; - esac - fi - done } run_rc_command "$1"