From d99cfa9588cee532eca58f709dfa7de2c1e691cc Mon Sep 17 00:00:00 2001 From: ssm Date: Wed, 16 May 2007 11:38:08 +0000 Subject: [PATCH] Init-script: * Move user-adjustable parts from init script to defaults file, expect $DAEMON_OPTS instead of a whole forest of variables. * We have a pid file argument, wheee. :D Defaults file: * Created alternative default templates, selected a one-backend default without VCL file. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1431 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/debian/varnish.default | 133 ++++++++++++++++++--------- varnish-cache/debian/varnish.init | 97 +++++++++---------- 2 files changed, 135 insertions(+), 95 deletions(-) diff --git a/varnish-cache/debian/varnish.default b/varnish-cache/debian/varnish.default index b7d34aa2..74b58c73 100644 --- a/varnish-cache/debian/varnish.default +++ b/varnish-cache/debian/varnish.default @@ -1,44 +1,91 @@ # Configuration file for varnish - - -# Main configuration file. You probably want to change it :) -VARNISH_VCL_CONF=/etc/varnish/vcl.conf - -# Default address and port to bind to -VARNISH_LISTEN_ADDRESS=0.0.0.0 -VARNISH_LISTEN_PORT=6081 - - -# Telnet admin interface listen address and port -VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 -VARNISH_ADMIN_LISTEN_PORT=6082 - - -# The minimum number of threads to start -VARNISH_MIN_WORKER_THREADS=1 - - -# Maximum number of worker threads or INF for unlimited -VARNISH_MAX_WORKER_THREADS=2048 - - -# Timeout value in seconds for threads to return -VARNISH_WORKER_THREAD_TIMEOUT=10 - - -# Hash algorithm to be used -VARNISH_HASHOPTION=classic - - -# Maximum size of the backend storagefile in bytes -VARNISH_BACKEND_STORAGE_SIZE=10240000 -VARNISH_BACKEND_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin - - -# Backend storage specification -VARNISH_BACKEND_STORAGE="file,${VARNISH_BACKEND_STORAGE_FILE},${VARNISH_BACKEND_STORAGE_SIZE}" - - -# Set default ttl in secounds -VARNISH_TTL=120 - +# +# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this +# shell script fragment. +# + +# This file contains 4 alternatives, please use only one. + +## Alternative 1, Minimal configuration, no VCL +# +# Listen on localhost:6081, administration on localhost:6082, and forward to +# content server on localhost:8080. Use a fixed size file storage. +# +DAEMON_OPTS="-a localhost:6081 \ + -T localhost:6082 \ + -b localhost:8080 \ + -s file,/var/lib/varnish/varnish_storage.bin,10485760" + + +## Alternative 2, Configuration with VCL +# +# Listen on localhost:6081, administration on localhost:6082, and forward to +# one content server selected by the vcl file, based on the request. Use a +# fixed size file storage. +# +# DAEMON_OPTS="-a localhost:6081 \ +# -T localhost:6082 \ +# -f /etc/varnish/default.vcl \ +# -s file,/var/lib/varnish/varnish_storage.bin,10485760" + + +## Alternative 3, Advanced configuration +# +# See varnishd(1) for more information. +# +# # Main configuration file. You probably want to change it :) +# VARNISH_VCL_CONF=/etc/varnish/default.vcl +# +# # Default address and port to bind to +# VARNISH_LISTEN_ADDRESS=0.0.0.0 +# VARNISH_LISTEN_PORT=6081 +# +# +# # Telnet admin interface listen address and port +# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 +# VARNISH_ADMIN_LISTEN_PORT=6082 +# +# +# # The minimum number of threads to start +# VARNISH_MIN_WORKER_THREADS=1 +# +# +# # Maximum number of worker threads or INF for unlimited +# VARNISH_MAX_WORKER_THREADS=2048 +# +# +# # Timeout value in seconds for threads to return +# VARNISH_WORKER_THREAD_TIMEOUT=10 +# +# +# # Hash algorithm to be used +# VARNISH_HASHOPTION=classic +# +# +# # Maximum size of the backend storagefile in bytes +# VARNISH_BACKEND_STORAGE_SIZE=10240000 +# VARNISH_BACKEND_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin +# +# +# # Backend storage specification +# VARNISH_BACKEND_STORAGE="file,${VARNISH_BACKEND_STORAGE_FILE},${VARNISH_BACKEND_STORAGE_SIZE}" +# +# +# # Set default ttl in secounds +# VARNISH_TTL=120 +# +# # DAEMON_OPTS is used by the init script. If you add or remove options, make +# # sure you update this section, too. +# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ +# -h ${VARNISH_HASHOPTION} \ +# -f ${VARNISH_VCL_CONF} \ +# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ +# -t ${VARNISH_TTL} \ +# -w ${VARNISH_MIN_WORKER_THREADS},${VARNISH_MAX_WORKER_THREADS},${VARNISH_WORKER_THREAD_TIMEOUT} \ +# -s ${VARNISH_BACKEND_STORAGE}" +# + + +## Alternative 4, Do It Yourself +# +# DAEMON_OPTS="" diff --git a/varnish-cache/debian/varnish.init b/varnish-cache/debian/varnish.init index b4cff3d4..7b2cfc48 100644 --- a/varnish-cache/debian/varnish.init +++ b/varnish-cache/debian/varnish.init @@ -1,34 +1,28 @@ #! /bin/sh # -# skeleton example file to build /etc/init.d/ scripts. -# This file should be used to construct scripts for /etc/init.d. -# -# Written by Miquel van Smoorenburg . -# Modified for Debian -# by Ian Murdock . -# -# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl -# +# varnish Control the varnish HTTP accelerator ### BEGIN INIT INFO # Provides: varnish # Required-Start: $local_fs $network # Required-Stop: $local_fs $network -# Should-Start: $remote_fs -# Should-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: Start HTTPd accelerator +# Short-Description: Start HTTP accelerator # Description: This script provides a server-side cache # to be run in front of a httpd and should -# listen on port 80 on a properly configured +# listen on port 80 on a properly configured # system ### END INIT INFO -NAME=varnish -DESC="HTTPd accelerator" +# Source function library +. /lib/lsb/init-functions + +NAME=varnishd +DESC="HTTP accelerator" PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/varnishd +PIDFILE=/var/run/$NAME.pid test -x $DAEMON || exit 0 @@ -37,45 +31,44 @@ if [ -f /etc/default/varnish ] ; then . /etc/default/varnish fi -DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \ - -h ${VARNISH_HASHOPTION} \ - -f ${VARNISH_VCL_CONF} \ - -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ - -t ${VARNISH_TTL} \ - -w ${VARNISH_MIN_WORKER_THREADS},${VARNISH_MAX_WORKER_THREADS},${VARNISH_WORKER_THREAD_TIMEOUT} \ - -s ${VARNISH_BACKEND_STORAGE}" - -set -e +# If $DAEMON_OPTS is not set at all in /etc/default/varnish, use minimal useful +# defaults (Backend at localhost:8080, a common place to put a locally +# installed application server.) +DAEMON_OPTS=${DAEMON_OPTS:--b localhost} case "$1" in - start) - echo -n "Starting $DESC: " - start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ - --exec $DAEMON -- $DAEMON_OPTS 2>&1 > /dev/null - echo "$NAME." - ;; - stop) - echo -n "Stopping $DESC: " - pkill varnishd - echo "$NAME." - ;; - restart|force-reload) - # - # If the "reload" option is implemented, move the "force-reload" - # option to the "reload" entry above. If not, "force-reload" is - # just the same as "restart". - # - echo -n "Restarting $DESC: " - pkill varnishd - sleep 1 - start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ - --exec $DAEMON -- $DAEMON_OPTS 2>&1 > /dev/null - echo "$NAME." - ;; - *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|force-reload}" >&2 - exit 1 + start) + output=$(/bin/tempfile -s.varnish) + log_daemon_msg "Starting $DESC" + log_progress_msg $NAME + if start-stop-daemon \ + --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ + -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1; then + log_end_msg 0 + else + log_end_msg 1 + cat $output + fi + rm $output + ;; + stop) + log_daemon_msg "Stopping $DESC" + log_progress_msg $NAME + if start-stop-daemon \ + --stop --quiet --pidfile $PIDFILE --oknodo --retry 10 \ + --exec $DAEMON; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + restart|force-reload) + $0 stop + $0 start + ;; + *) + log_success_msg "Usage: $0 {start|stop|restart|force-reload}" + exit 1 ;; esac -- 2.39.5