PIDFILE=/var/run/varnishd.pid
+# import some env from parent process
+if [ -f /proc/$PPID/environ ]; then
+ eval $(tr '\0' '\n' < /proc/$PPID/environ | grep -E '^(USER|SUDO_USER|LOGNAME)=')
+ LOGNAME=${SUDO_USER:-${LOGNAME:-$USER}}
+fi
+
# Generate a label, prefixed with the caller's username, from the
# kernel random uuid generator, fallback to timestamp
if [ -f /proc/sys/kernel/random/uuid ]; then
read uuid < /proc/sys/kernel/random/uuid
- vcl_label="${LOGNAME}${LOGNAME:+:}${uuid}"
+ vcl_label="$(date +${LOGNAME}${LOGNAME:+:}%Y-%m-%d:%H.%M:${uuid})"
else
- vcl_label="$($date +${LOGNAME}${LOGNAME:+:}%s.%N)"
+ vcl_label="$(date +${LOGNAME}${LOGNAME:+:}%s.%N)"
fi
+varnishadm() {
+ /usr/bin/varnishadm -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} "$@"
+}
# for simplier code
vcl_load() {
- /usr/bin/varnishadm -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} vcl.load "$@"
+ varnishadm vcl.load "$@"
}
vcl_use() {
- /usr/bin/varnishadm -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} vcl.use "$@"
+ varnishadm vcl.use "$@"
}
vcl_discard() {
- /usr/bin/varnishadm -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} vcl.discard "$@"
+ varnishadm vcl.discard "$@"
}
# configtest itself
# default limits
SERVICE_LIMITS="${SERVICE_LIMIS:--n $NFILES -l $MEMLOCK}"
- # DAEMON_OPTS is used by the init script. If you add or remove options, make
+ # 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}
# checkconfig needs running varnish
checkconfig
fi
- stop
+ stop
start
}
checkconfig|configtest)
checkconfig 1
;;
+ varnishadm)
+ shift
+ varnishadm "$@"
+ ;;
status)
status --pidfile $PIDFILE varnishd
RETVAL=$?
;;
*)
- msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
+ msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|varnishadm|status}"
exit 3
esac