summaryrefslogtreecommitdiff
path: root/www/varnish6/files/varnishncsa.in
blob: 6aa8115b56cde32b129279f13e0f2884470c846e (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: varnishncsa
# REQUIRE: DAEMON varnishd
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable varnishncsa:
#
# varnishncsa_enable="YES"
#
# Configuration variables and their default values:
#
# varnishncsa_pidfile - full path to the PID file.
#	default: "/var/run/varnishncsa.pid"
#
# varnishncsa_file - full path to the log file.
#	default: "/var/log/varnishncsa.log"
#
# varnishncsa_log_method - log to file or syslog
#       default: "-D -a -w ${varnishncsa_file}"
#       varnishncsa_syslog="YES": '| /usr/bin/logger -t varnish -p daemon.info &'
#
# varnishncsa_flags - command line arguments.
#	default: "-t off -P ${varnishncsa_pidfile} ${varnishncsa_logformat:+ -F \"$varnishncsa_logformat\"} ${varnishncsa_log_method}"
#
# varnishncsa_logformat - log file format.
#       default: "" (uses varnishncsa's default format)
#       example: "%h %l %u %t %r %s %b %{Referer}i %{User-agent}i"
#
# Add the following line to /etc/newsyslog.conf to rotate the log file
# once a day:
#
# /var/log/varnishncsa.log varnishlog:varnish 640 7 * @T00 JB /var/run/varnishncsa.pid
#
# See varnishncsa(1) for a detailed overview of command-line options.
#

. /etc/rc.subr

name=varnishncsa
rcvar=varnishncsa_enable

load_rc_config ${name}

: ${varnishncsa_enable:=NO}
: ${varnishncsa_pidfile=/var/run/${name}.pid}
: ${varnishncsa_file=/var/log/${name}.log}
: ${varnishncsa_flags="-t off -P ${varnishncsa_pidfile} ${varnishncsa_logformat:+-F \"$varnishncsa_logformat\"}"}
: ${varnishncsa_syslog:=NO}

if checkyesno varnishncsa_syslog; then
    varnishncsa_log_method='| /usr/bin/logger -t varnish -p daemon.info &'
else
    varnishncsa_log_method="-D -a -w ${varnishncsa_file}"
fi

command="%%PREFIX%%/bin/${name}"
command_args="${varnishncsa_flags} ${varnishncsa_log_method}"
pidfile=${varnishncsa_pidfile}
start_precmd=precmd

precmd()
{
        # $varnishncsa_flags gets applied too early if we don't do this.
        rc_flags=""

	if [ ! -e ${pidfile} ]; then
		install -o varnishlog -g varnish -m 644 /dev/null ${pidfile};
	fi

	if [ ! -e ${varnishncsa_file} ]; then
		install -o varnishlog -g varnish -m 640 /dev/null ${varnishncsa_file};
	fi
}

run_rc_command "$1"