diff options
author | Mark Felder <feld@FreeBSD.org> | 2015-05-08 13:24:35 +0000 |
---|---|---|
committer | Mark Felder <feld@FreeBSD.org> | 2015-05-08 13:24:35 +0000 |
commit | e5e4ea1fd033e29185f8127319c2fa2694acc8ed (patch) | |
tree | eb54dde0f8c8b68043e9353f338ec5d53f7c1416 /net | |
parent | 191ff781a0183230f1b47496d193384a70ad2061 (diff) | |
download | freebsd-ports-e5e4ea1fd033e29185f8127319c2fa2694acc8ed.zip |
Improve configuration and setup of vnstat through the rc script
PR: 199133
Diffstat (limited to 'net')
-rw-r--r-- | net/vnstat/Makefile | 1 | ||||
-rw-r--r-- | net/vnstat/files/pkg-message.in | 9 | ||||
-rw-r--r-- | net/vnstat/files/vnstat.in | 25 |
3 files changed, 34 insertions, 1 deletions
diff --git a/net/vnstat/Makefile b/net/vnstat/Makefile index a13e32eb5301..615d318ffe79 100644 --- a/net/vnstat/Makefile +++ b/net/vnstat/Makefile @@ -3,6 +3,7 @@ PORTNAME= vnstat PORTVERSION= 1.12 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= http://humdi.net/vnstat/ \ http://mirror.mcx2.org/ diff --git a/net/vnstat/files/pkg-message.in b/net/vnstat/files/pkg-message.in index 202fe8bbbbb3..327385460a7d 100644 --- a/net/vnstat/files/pkg-message.in +++ b/net/vnstat/files/pkg-message.in @@ -1,7 +1,14 @@ ########################################################################### vnstat has been installed. -A Sample configuration file has be installed in %%PREFIX%%/etc/ +A sample configuration file has been installed in %%PREFIX%%/etc/ +Please add your default network interface in the 'Interface' line there +before starting vnstat service. +You can add any number of additional interfaces either in +vnstat_additional_ifaces variable in /etc/rc.conf, or with this command: +su -m %%USERS%% -c "%%PREFIX%%/bin/vnstat --create --iface <your interface>" +and restart vnstat service: +service vnstat restart For more information about vnStat use "man vnstat" or visit: http://humdi.net/vnstat/ diff --git a/net/vnstat/files/vnstat.in b/net/vnstat/files/vnstat.in index ca804433d9c2..f4b9263748f8 100644 --- a/net/vnstat/files/vnstat.in +++ b/net/vnstat/files/vnstat.in @@ -9,6 +9,7 @@ # Add the following line to /etc/rc.conf to enable vnstat: # # vnstat_enable="YES" +# vnstat_additional_ifaces="em1" . /etc/rc.subr @@ -26,11 +27,23 @@ load_rc_config $name command="%%PREFIX%%/sbin/vnstatd" command_args="-p ${vnstat_pidfile} --config ${vnstat_config}" pidfile="${vnstat_pidfile}" +user_cmd="%%PREFIX%%/bin/vnstat" start_precmd=vnstat_startprecmd +create_iface_database() +{ + local iface="$1" + local descr="$2" + su -m ${vnstat_user} -c "${user_cmd} --create --iface $iface" >/dev/null 2>&1 || + ! echo "$name: Failed to create database for the $descr interface $iface" || return 1 + echo "$name: Created the database for the $descr interface $iface" +} + vnstat_startprecmd() { + local dbdir iface + if [ ! -e ${pidfile%/*} ]; then install -d -o ${vnstat_user} -g ${vnstat_group} ${pidfile%/*}; fi @@ -40,6 +53,18 @@ vnstat_startprecmd() install -d -o ${vnstat_user} -g ${vnstat_group} ${dbdir}; fi + iface=$(grep "^Interface" ${vnstat_config} | head -1 | awk 'BEGIN{FS="\042"}{print $2}') + if [ -n "${iface}" -a ! -f ${dbdir}/${iface} ]; then + create_iface_database $iface "default" || return 1 + fi + if [ -n "${vnstat_additional_ifaces}" ]; then + for iface in ${vnstat_additional_ifaces}; do + if [ ! -f ${dbdir}/${iface} ]; then + create_iface_database $iface "additional" || return 1 + fi + done + fi + if [ ! -d "/var/run/vnstat" ]; then install -d -o ${vnstat_user} -g ${vnstat_group} /var/run/vnstat; fi |