diff options
Diffstat (limited to 'www-servers/varnish/files/varnishd.initd-r2')
-rwxr-xr-x | www-servers/varnish/files/varnishd.initd-r2 | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/www-servers/varnish/files/varnishd.initd-r2 b/www-servers/varnish/files/varnishd.initd-r2 new file mode 100755 index 000000000000..055a9ec0405a --- /dev/null +++ b/www-servers/varnish/files/varnishd.initd-r2 @@ -0,0 +1,94 @@ +#!/sbin/runscript +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +extra_commands="configtest" +extra_started_commands="reload" + +description_configtest="Run syntax tests for configuration files." +description_reload="Reloads the configuration." + +depend() { + need net +} + +configtest() { + ebegin "Checking ${SVCNAME} configuration" + checkconfig + eend $? +} + +checkconfig() { + ${VARNISHD} -C -f ${CONFIGFILE} >/dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + eerror "${SVCNAME} has detected an error in your setup:" + ${VARNISHD} -C -f ${CONFIGFILE} + fi + + return $ret +} + +start() { + checkconfig || return 1 + + ebegin "Starting varnish" + start-stop-daemon --quiet --start --pidfile /run/varnishd.pid \ + --exec ${VARNISHD} -- \ + -P /run/varnishd.pid \ + ${VARNISHD_OPTS} &> /dev/null + eend $? + + if [ "${VARNISHNCSA_ARGS}" != "" ]; then + ebegin "Starting varnish logging" + start-stop-daemon --quiet --start --pidfile /run/varnishncsa.pid \ + --exec /usr/bin/varnishncsa -- \ + -D -P /run/varnishncsa.pid \ + ${VARNISHNCSA_ARGS} \ + ${VARNISHNCSA_LOGFORMAT:+-F "${VARNISHNCSA_LOGFORMAT}"} + eend $? + fi +} + +stop() { + ebegin "Stopping varnish" + start-stop-daemon --quiet --stop --pidfile /run/varnishd.pid + eend $? + + if [ -e /run/varnishncsa.pid ]; then + ebegin "Stopping varnish logging" + start-stop-daemon --quiet --stop --pidfile /run/varnishncsa.pid + eend $? + fi +} + +reload() { + checkconfig || return 1 + + ebegin "Reloading varnish" + + $VARNISHADM vcl.list >/dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + eerror "${SVCNAME} cannot list configuration" + return 1 + fi + + new_config="reload_$(date +%FT%H:%M:%S)" + $VARNISHADM vcl.load $new_config $CONFIGFILE >/dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + eerror "${SVCNAME} cannot load configuration" + return 1 + fi + + $VARNISHADM vcl.use $new_config >/dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + eerror "${SVCNAME} cannot switch configuration" + return 1 + fi + + eend 0 +} |