Reputation: 2061
Varnish fails to start using:
service varnish start
without any errors, but runs fine when I do:
varnishd -f /etc/varnish/user.vcl -s malloc,1G -T localhost:6082 -a 0.0.0.0:6081 -d
This is /etc/default/varnish
:
START=yes
NFILES=131072
MEMLOCK=82000
DAEMON_OPTS="-a 0.0.0.0:6081 \
-T localhost:6082 \
-f /etc/varnish/user.vcl \
-S /etc/varnish/secret \
-s malloc,1024m"
I'm on Ubuntu 16.04. Any thoughts?
Version:
# varnishd -V
varnishd (varnish-4.1.1 revision 66bb824)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2015 Varnish Software AS
This is syslog
:
Nov 30 14:16:46 **** systemd[1]: Started Varnish HTTP accelerator.
Nov 30 14:16:46 **** varnishd[28089]: Error: Cannot open socket: :6081: Address family not supported by protocol
Nov 30 14:16:46 **** systemd[1]: varnish.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 30 14:16:46 **** systemd[1]: varnish.service: Unit entered failed state.
Nov 30 14:16:46 **** systemd[1]: varnish.service: Failed with result 'exit-code'.
/etc/init.d/varnish
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: varnish
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# 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
# system
### END INIT INFO
# Source function library
. /lib/lsb/init-functions
NAME=varnishd
DESC="HTTP accelerator"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/varnishd
PIDFILE=/run/$NAME.pid
test -x $DAEMON || exit 0
# Include varnish defaults if available
if [ -f /etc/default/varnish ] ; then
. /etc/default/varnish
fi
# Open files (usually 1024, which is way too small for varnish)
ulimit -n ${NFILES:-131072}
# Maxiumum locked memory size for shared memory log
ulimit -l ${MEMLOCK:-82000}
# 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}
# Ensure we have a PATH
export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin:/sbin:/bin"
start_varnishd() {
log_daemon_msg "Starting $DESC" "$NAME"
output=$(/bin/tempfile -s.varnish)
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
exit 1
fi
rm $output
}
disabled_varnishd() {
log_daemon_msg "Not starting $DESC" "$NAME"
log_progress_msg "disabled in /etc/default/varnish"
log_end_msg 0
}
stop_varnishd() {
log_daemon_msg "Stopping $DESC" "$NAME"
if start-stop-daemon \
--stop --quiet --pidfile $PIDFILE --retry 10 \
--exec $DAEMON; then
log_end_msg 0
else
log_end_msg 1
fi
if test -r $PIDFILE; then
read -r PID < $PIDFILE
if test ! -d /proc/$PID ; then
# stale pidfile
unset PID
rm -f $PIDFILE
fi
fi
}
reload_varnishd() {
log_daemon_msg "Reloading $DESC" "$NAME"
if /usr/share/varnish/reload-vcl -q; then
log_end_msg 0
else
log_end_msg 1
fi
}
status_varnishd() {
start-stop-daemon \
--status --quiet --pidfile $PIDFILE \
--exec $DAEMON
exit $?
}
configtest() {
$DAEMON ${DAEMON_OPTS} -C -n /tmp > /dev/null
}
case "$1" in
start)
case "${START:-}" in
[Yy]es|[Yy]|1|[Tt]|[Tt]rue)
start_varnishd
;;
*)
disabled_varnishd
;;
esac
;;
stop)
stop_varnishd
;;
reload)
reload_varnishd
;;
status)
status_varnishd
;;
restart|force-reload)
if status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" 1>/dev/null; then
if ! configtest; then
log_failure_msg "Syntax check failed, not restarting"
exit 1
fi
fi
$0 stop
$0 start
;;
configtest)
configtest && log_success_msg "Syntax ok"
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|reload|force-reload|configtest}"
exit 1
;;
esac
Upvotes: 3
Views: 7167
Reputation: 91
I ran into the exact same issue moving my production environment to a less... ancient Opsworks/Chef stack with Ubuntu.
It turned out that the docs on the Varnish site were not quite complete for Ubuntu 16+, you need a few other command line switches. This is what works for me:
[Service]
ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
The -F
switch moves it into the foreground, which I've found helps with systemctl services.
The -j
switch enables the Varnish privilege jail (more on that here: https://www.varnish-cache.org/docs/4.1/reference/varnishd.html?highlight=jail#jail).
Upvotes: 3
Reputation: 1778
You're mixing old configuration steps with the new. Ubuntu 16.04 uses Systemd, making /etc/default/varnish and /etc/init.d/varnish files obsolete.
After a lot of searching and running into this issue myself, I found that this tutorial works best and uses best practises:
https://www.cyberciti.biz/faq/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts/
Upvotes: 0
Reputation: 4065
It seems to not like the 0.0.0.0:6081
address for the admin part.
Nov 30 14:16:46 **** varnishd[28089]: Error: Cannot open socket: :6081: Address family not supported by protocol
Change your daemon_opt part to -a :80
in /etc/default/varnish
Upvotes: -1