--- varnishd 2013-11-08 20:55:46.445981048 +0100 +++ varnishd.new 2013-11-08 20:56:34.149313522 +0100 @@ -9,6 +9,26 @@ description_configtest="Run syntax tests for configuration files." description_reload="Reloads the configuration." +CONF="${SVCNAME#*.}" +CONFBASE="/etc/conf.d/varnishd" +[ -z "${PIDBASE}" ] && PIDBASE="/var/run/varnishd" +[ "${CONF}" = "varnishd" ] && CONF='' + +if [ -n "${CONF}" ]; then + PIDFILE="${PIDBASE}.${CONF}.pid" + CONFSRC="${CONFBASE}.${CONF}" + INSTANCE="${CONF}" + if [ -f "${CONFSRC}" ]; then + . "${CONFSRC}" + else + eerror "The configuration file $CONFSRC was not found!" + fi +else + PIDFILE="${PIDBASE}.pid" + CONFSRC="${CONFBASE}" + INSTANCE="${HOSTNAME}" +fi + depend() { need net } @@ -34,24 +54,24 @@ checkconfig || return 1 ebegin "Starting varnish" - start-stop-daemon --quiet --start --pidfile /var/run/varnishd.pid --exec ${VARNISHD} -- -P /var/run/varnishd.pid ${VARNISHD_OPTS} &> /dev/null + start-stop-daemon --quiet --start --pidfile ${PIDFILE} --exec ${VARNISHD} -- -n ${INSTANCE} -P ${PIDFILE} ${VARNISHD_OPTS} &> /dev/null eend $? if [ "${VARNISHNCSA_ARGS}" != "" ]; then ebegin "Starting varnish logging" - start-stop-daemon --quiet --start --pidfile /var/run/varnishncsa.pid --exec /usr/bin/varnishncsa -- -D -P /var/run/varnishncsa.pid ${VARNISHNCSA_ARGS} + start-stop-daemon --quiet --start --pidfile ${PIDFILE}.ncsa --exec /usr/bin/varnishncsa -- -n ${INSTANCE} -D -P ${PIDFILE}.ncsa ${VARNISHNCSA_ARGS} eend $? fi } stop() { ebegin "Stopping varnish" - start-stop-daemon --quiet --stop --pidfile /var/run/varnishd.pid + start-stop-daemon --quiet --stop --pidfile ${PIDFILE} eend $? - if [ -e /var/run/varnishncsa.pid ]; then + if [ -e ${PIDFILE}.ncsa ]; then ebegin "Stopping varnish logging" - start-stop-daemon --quiet --stop --pidfile /var/run/varnishncsa.pid + start-stop-daemon --quiet --stop --pidfile ${PIDFILE}.ncsa eend $? fi } @@ -61,7 +81,7 @@ ebegin "Reloading varnish" - $VARNISHADM vcl.list >/dev/null 2>&1 + $VARNISHADM -n ${INSTANCE} vcl.list >/dev/null 2>&1 ret=$? if [ $ret -ne 0 ]; then eerror "${SVCNAME} cannot list configuration" @@ -69,14 +89,14 @@ fi new_config="reload_$(date +%FT%H:%M:%S)" - $VARNISHADM vcl.load $new_config $CONFIGFILE >/dev/null 2>&1 + $VARNISHADM -n ${INSTANCE} 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 + $VARNISHADM -n ${INSTANCE} vcl.use $new_config >/dev/null 2>&1 ret=$? if [ $ret -ne 0 ]; then eerror "${SVCNAME} cannot switch configuration"