Project

General

Profile

Actions

Bug #4282

closed

Vnstat2 1.11 Does Configuration Parser Error

Added by Bryce Chidester about 9 years ago. Updated about 9 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
01/24/2015
Due date:
% Done:

0%

Estimated time:
Plus Target Version:
Affected Version:
2.2
Affected Plus Version:
Affected Architecture:

Description

Since upgrading to 2.2 (and reinstalling all packages), vnstat2 errors out every time.

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin>
X-Cron-Env: <HOME=/var/log>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

Error: Unable to open database directory "/var/lib/vnstat".
Make sure it exists and is at least read enabled for current user.
Exiting...

If I add --debug to the vnstat invocation in /usr/local/pkg/vnstat2/vnstat2.sh I see that the DatabaseDir directive vnstat is using, and supposedly reading from the correct configuration file does not match the actual contents of that configuration file.

Config file: /usr/local/etc/vnstat.conf
  c: Interface "eth0" 
   -> "Interface": "eth0" 
  c: DatabaseDir "/var/lib/vnstat" 
   -> "DatabaseDir": "/var/lib/vnstat" 
  c: Locale "-" 
   -> "Locale": "-" 
  i: MonthRotate 1
   -> "MonthRotate": 1
  c: DayFormat    "%x" 
   -> "DayFormat": "%x" 
  c: MonthFormat  "%b '%y" 
   -> "MonthFormat": "%b '%y" 
  c: TopFormat    "%x" 
   -> "TopFormat": "%x" 
  c: RXCharacter       "%" 
   -> "RXCharacter": "%" 
  c: TXCharacter       ":" 
   -> "TXCharacter": ":" 
  c: RXHourCharacter   "r" 
   -> "RXHourCharacter": "r" 
  c: TXHourCharacter   "t" 
   -> "TXHourCharacter": "t" 
  i: UnitMode 0
   -> "UnitMode": 0
  i: OutputStyle 3
   -> "OutputStyle": 3
  i: RateUnit 1
   -> "RateUnit": 1
  i: MaxBandwidth 100
   -> "MaxBandwidth": 100
  i: Sampletime 5
   -> "Sampletime": 5
  i: QueryMode 0
   -> "QueryMode": 0
  i: CheckDiskSpace 1
   -> "CheckDiskSpace": 1
  i: UseFileLocking 1
   -> "UseFileLocking": 1
  i: BootVariation 15
   -> "BootVariation": 15
  i: TrafficlessDays 1
   -> "TrafficlessDays": 1
  i: UpdateInterval 30
   -> "UpdateInterval": 30
  i: PollInterval 5
   -> "PollInterval": 5
  i: SaveInterval 5
   -> "SaveInterval": 5
  i: OfflineSaveInterval 30
   -> "OfflineSaveInterval": 30
  i: SaveOnStatusChange 1
   -> "SaveOnStatusChange": 1
  i: UseLogging 2
   -> "UseLogging": 2
  c: LogFile "/var/log/vnstat.log" 
   -> "LogFile": "/var/log/vnstat.log" 
  c: PidFile "/var/run/vnstat.pid" 
   -> "PidFile": "/var/run/vnstat.pid" 
  c: HeaderFormat "%x %H:%M" 
   -> "HeaderFormat": "%x %H:%M" 
  i: HourlyRate 1
   -> "HourlyRate": 1
  i: SummaryRate 1
   -> "SummaryRate": 1
  i: SummaryLayout 1
   -> "SummaryLayout": 1
  i: TransparentBg 0
   -> "TransparentBg": 0
  c: CBackground     "FFFFFF" 
   -> "CBackground": "FFFFFF" 
  c: CEdge           "AEAEAE" 
   -> "CEdge": "AEAEAE" 
  c: CHeader         "606060" 
   -> "CHeader": "606060" 
  c: CHeaderTitle    "FFFFFF" 
   -> "CHeaderTitle": "FFFFFF" 
  c: CHeaderDate     "FFFFFF" 
   -> "CHeaderDate": "FFFFFF" 
  c: CText           "000000" 
   -> "CText": "000000" 
  c: CLine           "B0B0B0" 
   -> "CLine": "B0B0B0" 
  c: CLineL          "-" 
   -> "CLineL": "-" 
  c: CRx             "92CF00" 
   -> "CRx": "92CF00" 
  c: CTx             "606060" 
   -> "CTx": "606060" 
  c: CRxD            "-" 
   -> "CRxD": "-" 
  c: CTxD            "-" 
   -> "CTxD": "-" 
ibw list is empty.
arg 1: "--debug" 
arg 2: "-u" 
Updating database...
Error: Unable to open database directory "/var/lib/vnstat".
Make sure it exists and is at least read enabled for current user.
Exiting...

Actual /usr/local/etc/vnstat.conf

# vnStat 1.10 config file
##

# location of the database directory
DatabaseDir "/conf/vnstat" 

# on which day should months change
MonthRotate 1

# vnstati
##

# image colors
CBackground     "F0F0F0" 
CEdge           "AEAEAE" 
CHeader         "990000" 
CHeaderTitle    "F0F0F0" 
CHeaderDate     "FFFFFF" 
CText           "000000" 
CLine           "B0B0B0" 
CLineL          "-" 
CRx             "666666" 
CTx             "990000" 
CRxD            "-" 
CTxD            "-" 

After some digging, I found /usr/pbi/vnstat-i386/local/etc/vnstat.conf whose contents match the --debug output exactly.

From this I conclude that this is a bug in vnstat 1.11 reporting that it's reading the correct file but in actuality reading/parsing a different and incorrect file. Even after passing the correct file with --config, the behaviour continues.
After upgrading to vnstat 1.12 (from FreeBSD packages), the issue is resolved.

Clearly this is an upstream bug that has since been squashed. A simple package upgrade to match FreeBSD's 1.12 should resolve the issue completely.

Actions #1

Updated by Bryce Chidester about 9 years ago

(Wow, I meant to update the title slightly... I promise, I speak better English)

Obligatory patch to pfsense-packages. I admit this was a simple swap of 1.11 for 1.12 and I've not tested it.

diff --git a/pkg_config.10.xml b/pkg_config.10.xml
index a0057bf..a65e19f 100644
--- a/pkg_config.10.xml
+++ b/pkg_config.10.xml
@@ -587,11 +587,11 @@
                <descr>Vnstat is a console-based network traffic monitor&lt;br /&gt;The vnstat PHP frontend and vnstati adds a more user friendly way of displaying traffic usage.</descr>
                <pkginfolink>https://forum.pfsense.org/index.php/topic,14179.0.html</pkginfolink>
                <category>Network Management</category>
-               <depends_on_package_pbi>vnstat-1.11_6-##ARCH##.pbi</depends_on_package_pbi>
+               <depends_on_package_pbi>vnstat-1.12_6-##ARCH##.pbi</depends_on_package_pbi>
                <build_pbi>
                        <port>net/vnstat</port>
                </build_pbi>
-               <version>1.11_6,2</version>
+               <version>1.12_6,2</version>
                <status>Stable</status>
                <required_version>2.2</required_version>
                <maintainer>crazypark2@yahoo.dk</maintainer>

Actions #2

Updated by Disk1of5 NA about 9 years ago

I can confirm, this bug as well Vnstat2 installs correctly but no logs are ever updated. after going into the shell and starting it manually this is the output:

[2.2-RELEASE][]/usr/local/etc: pwd
/usr/local/etc
[2.2-RELEASE][]/usr/local/etc: vnstatd -n --config vnstat.conf
Error: Unable to open database directory "/var/lib/vnstat".
Make sure it exists and is at least read enabled for current user.
Exiting...

Actions #3

Updated by Bryce Chidester about 9 years ago

After digging into this further, this is a "feature" of the PBI architecture, and a bug in the package. The PBI middleware silently rewrites/redirects file access into the PBI prefix, taking /usr and turning it into /usr/pbi/vnstat-$arch. The package installs a symlink in an attempt to redirect the /usr/local/etc/vnstat.conf into the PBI directory for the binary to use. However, this symlink is only installed after package installation, but gets destroyed when the file is overwritten by the configuration page. Therefore, the solution is to reinstall the symlink as a matter of course in writing the configuration file.

My earlier test that indicated the fault was with the vnstat package itself was unfortunately faulty. I compared a stock binary to a PBI binary's behaviour, disregarding the various "features" of the PBI middleware. I'm sorry for the red herring this was.

The linked pullreq fixes this, and has been tested. https://github.com/pfsense/pfsense-packages/pull/794

Actions #4

Updated by Bipin Chandra about 9 years ago

i tested this and it seems to solve the issue

Actions #5

Updated by Jim Pingle about 9 years ago

Don't forget to also check that the package continues to work on 2.1.x with the fix applied. If it does not, then more code would need to be added to retain the current behavior on the old version.

Actions #6

Updated by Disk1of5 NA about 9 years ago

Is there a status update to when the pull request will be accepted, as it stands right now VNSTAT2 package is completely broke in 2.2

Actions #7

Updated by Paul K about 9 years ago

Here is a quick fix that you can apply to get it working until patch is merged.

64-bit run: ln -sf /usr/local/etc/vnstat.conf /usr/pbi/vnstat-amd64/etc/vnstat.conf
32-bit run: ln -sf /usr/local/etc/vnstat.conf /usr/pbi/vnstat-i386/etc/vnstat.conf

Actions #8

Updated by Bipin Chandra about 9 years ago

me too agree its completely broken and the patch provided by bryce needs to be merged

Actions #9

Updated by Jim Pingle about 9 years ago

It's just waiting on one of use to have enough time to test it to make sure it works and also doesn't break 2.1.x.

Actions #10

Updated by Jim Pingle about 9 years ago

  • Status changed from New to Feedback

Update the package and try again, I pushed some fixes earlier today. It works for me in testing here.

Actions #11

Updated by Paul K about 9 years ago

Tested on v2.2 amd64 full install.

Removed existing version, made sure nothing but settings are left behind and installed latest version. Frontend, command line tools and cron job all are working fine.

Thanks Jim and Bryce.

Actions #12

Updated by Chris Buechler about 9 years ago

  • Status changed from Feedback to Resolved

thanks for the confirmation Paul, and Jim and Bryce for fixing. Others have confirmed fixed as well.

Actions

Also available in: Atom PDF