Index: head/net/vnstat/Makefile =================================================================== --- head/net/vnstat/Makefile (revision 385776) +++ head/net/vnstat/Makefile (revision 385777) @@ -1,72 +1,73 @@ # Created by: Dennis Herrmann # $FreeBSD$ PORTNAME= vnstat PORTVERSION= 1.12 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= http://humdi.net/vnstat/ \ http://mirror.mcx2.org/ MAINTAINER= feld@FreeBSD.org COMMENT= Console-based network traffic monitor LICENSE= GPLv2 MAKE_ARGS= CC="${CC}" CFLAGS="-I${LOCALBASE}/include" \ LDFLAGS="-L${LOCALBASE}/lib" INSTALL_TARGET= bsdinstall USE_RC_SUBR= vnstat USES= gmake USERS= vnstat GROUPS= vnstat PORTDOCS= README INSTALL_BSD UPGRADE SUB_FILES= pkg-message SUB_LIST= USERS=${USERS} \ GROUPS=${GROUPS} # will compile with image output OPTIONS_DEFINE= GUI DOCS OPTIONS_DEFAULT= GUI GUI_DESC= Build with graphics/gd dependency .include .if ${PORT_OPTIONS:MGUI} LIB_DEPENDS+= libgd.so:${PORTSDIR}/graphics/gd PLIST_SUB+= GUI="" .else ALL_TARGET="vnstat" PLIST_SUB+= GUI="@comment " .endif post-patch: @${REINPLACE_CMD} -e 's|/etc/|${PREFIX}/etc/|g' \ ${WRKSRC}/src/cfg.c do-install: ${INSTALL_PROGRAM} ${WRKSRC}/src/vnstat ${STAGEDIR}/${PREFIX}/bin/vnstat ${INSTALL_PROGRAM} ${WRKSRC}/src/vnstatd ${STAGEDIR}/${PREFIX}/sbin/vnstatd ${INSTALL_DATA} ${WRKSRC}/cfg/vnstat.conf ${STAGEDIR}/${PREFIX}/etc/vnstat.conf.sample ${INSTALL_MAN} ${WRKSRC}/man/vnstat.1 ${STAGEDIR}/${MANPREFIX}/man/man1/vnstat.1 ${INSTALL_MAN} ${WRKSRC}/man/vnstatd.1 ${STAGEDIR}/${MANPREFIX}/man/man1/vnstatd.1 ${INSTALL_MAN} ${WRKSRC}/man/vnstat.conf.5 ${STAGEDIR}/${MANPREFIX}/man/man5/vnstat.conf.5 .if ${PORT_OPTIONS:MGUI} ${INSTALL_PROGRAM} ${WRKSRC}/src/vnstati ${STAGEDIR}/${PREFIX}/bin/vnstati ${INSTALL_MAN} ${WRKSRC}/man/vnstati.1 ${STAGEDIR}/${MANPREFIX}/man/man1/vnstati.1 .endif post-install: .if ${PORT_OPTIONS:MDOCS} @${ECHO_MSG} "installing additional documentation to ${DOCSDIR}" @${MKDIR} ${STAGEDIR}/${DOCSDIR} @cd ${WRKSRC} && ${INSTALL_DATA} ${PORTDOCS} ${STAGEDIR}/${DOCSDIR} .endif @${ECHO_MSG} "" @${CAT} ${PKGMESSAGE} @${ECHO_MSG} "" .include Index: head/net/vnstat/files/pkg-message.in =================================================================== --- head/net/vnstat/files/pkg-message.in (revision 385776) +++ head/net/vnstat/files/pkg-message.in (revision 385777) @@ -1,8 +1,15 @@ ########################################################################### 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/ ########################################################################### Index: head/net/vnstat/files/vnstat.in =================================================================== --- head/net/vnstat/files/vnstat.in (revision 385776) +++ head/net/vnstat/files/vnstat.in (revision 385777) @@ -1,48 +1,73 @@ #!/bin/sh # Created by: Mark Felder # $FreeBSD$ # PROVIDE: vnstat # REQUIRE: LOGIN # KEYWORD: shutdown # Add the following line to /etc/rc.conf to enable vnstat: # # vnstat_enable="YES" +# vnstat_additional_ifaces="em1" . /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 --noadd"} : ${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 +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 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 + + 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 } run_rc_command "$1"