summaryrefslogtreecommitdiff
path: root/net/vnstat/files/vnstat.in
blob: 63c4833c8d4cb0a0cb2e1084c766019a348281d6 (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
45
46
47
48
#!/bin/sh
# Created by: Mark Felder <feld@FreeBSD.org>

# PROVIDE: vnstat
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following line to /etc/rc.conf to enable vnstat:
#
# vnstat_enable="YES"

. /etc/rc.subr

name=vnstat
rcvar=vnstat_enable
load_rc_config $name

: ${vnstat_enable:=NO}
: ${vnstat_pidfile=/var/run/vnstat/vnstat.pid}
: ${vnstat_config=%%PREFIX%%/etc/vnstat.conf}
: ${vnstat_flags="-d"}
: ${vnstat_user:=%%USERS%%}
: ${vnstat_group:=%%GROUPS%%}

command="%%PREFIX%%/sbin/vnstatd"
command_args="-p ${vnstat_pidfile} --config ${vnstat_config}"
pidfile="${vnstat_pidfile}"
user_cmd="%%PREFIX%%/bin/vnstat"

start_precmd=vnstat_startprecmd

vnstat_startprecmd()
{
	if [ ! -e ${pidfile%/*} ]; then
		install -d -o ${vnstat_user} -g ${vnstat_group} ${pidfile%/*};
	fi

	dbdir=$(grep "^DatabaseDir" ${vnstat_config} | awk 'BEGIN{FS="\042"}{print $2}')
	if [ ! -d ${dbdir} ]; then
		install -d -o ${vnstat_user} -g ${vnstat_group} ${dbdir};
	fi

	if [ ! -d "/var/run/vnstat" ]; then
		install -d -o ${vnstat_user} -g ${vnstat_group} /var/run/vnstat;
	fi
}

run_rc_command "$1"