From owner-svn-ports-all@FreeBSD.ORG Fri May 8 13:24:37 2015 Return-Path: Delivered-To: svn-ports-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E8B94509; Fri, 8 May 2015 13:24:36 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D7675184D; Fri, 8 May 2015 13:24:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t48DOauS065675; Fri, 8 May 2015 13:24:36 GMT (envelope-from feld@FreeBSD.org) Received: (from feld@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t48DOa7M065668; Fri, 8 May 2015 13:24:36 GMT (envelope-from feld@FreeBSD.org) Message-Id: <201505081324.t48DOa7M065668@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: feld set sender to feld@FreeBSD.org using -f From: Mark Felder Date: Fri, 8 May 2015 13:24:36 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r385777 - in head/net/vnstat: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2015 13:24:37 -0000 Author: feld Date: Fri May 8 13:24:35 2015 New Revision: 385777 URL: https://svnweb.freebsd.org/changeset/ports/385777 Log: Improve configuration and setup of vnstat through the rc script PR: 199133 Modified: head/net/vnstat/Makefile head/net/vnstat/files/pkg-message.in head/net/vnstat/files/vnstat.in Modified: head/net/vnstat/Makefile ============================================================================== --- head/net/vnstat/Makefile Fri May 8 13:05:29 2015 (r385776) +++ head/net/vnstat/Makefile Fri May 8 13:24:35 2015 (r385777) @@ -3,6 +3,7 @@ PORTNAME= vnstat PORTVERSION= 1.12 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= http://humdi.net/vnstat/ \ http://mirror.mcx2.org/ Modified: head/net/vnstat/files/pkg-message.in ============================================================================== --- head/net/vnstat/files/pkg-message.in Fri May 8 13:05:29 2015 (r385776) +++ head/net/vnstat/files/pkg-message.in Fri May 8 13:24:35 2015 (r385777) @@ -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 " +and restart vnstat service: +service vnstat restart For more information about vnStat use "man vnstat" or visit: http://humdi.net/vnstat/ Modified: head/net/vnstat/files/vnstat.in ============================================================================== --- head/net/vnstat/files/vnstat.in Fri May 8 13:05:29 2015 (r385776) +++ head/net/vnstat/files/vnstat.in Fri May 8 13:24:35 2015 (r385777) @@ -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