aboutsummaryrefslogtreecommitdiffstats
path: root/main/varnish/varnishncsa.initd
blob: 8a584decc965ac251cfb81142a36faec00f64501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

VARNISHNCSA_PID=${VARNISHNCSA_PID:-/run/${SVCNAME}.pid}

command="${VARNISHNCSA:-/usr/bin/varnishncsa}"
command_args="-D -P ${VARNISHNCSA_PID} ${VARNISHNCSA_OPTS}"
pidfile="${VARNISHNCSA_PID}"

extra_started_commands="reload rotate flush"

description_rotate="Rotate the log file"
description_flush="Flush any outstanding transactions"

# We need to make sure varnishd has started first, bug #524284
start_pre() {
	TIMEOUT=${TIMEOUT:-5}

	local i=0
	while [ $i -lt ${TIMEOUT} ]; do
		echo status | varnishadm 2>/dev/null | grep -q "Child in state running"
		test $? -eq 0  && break

		sleep 1 && i=$(expr $i + 1)
	done
}

rotate() {
	ebegin "Rotating log file"
	start-stop-daemon -p ${VARNISHNCSA_PID} -s SIGHUP
	eend $?
}

flush() {
	ebegin "Flushing any outstanding transactions"
	start-stop-daemon -p ${VARNISHNCSA_PID} -s SIGUSR1
	eend $?
}

reload() {
	flush
	rotate
}