Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Monday, April 10, 2017 at 22:13


There was a problem for me after publishing the vnStat PHP article, it's vnStat console could not update its database automatically. The result was vnStat PHP cannot update the data automatically as well. The cause is probably because I accidentally ran vnstat update as root. But apparently the solution is easy. Just make the user of vnstatd daemon the owner of the database directory.


See The User


Actually, when vnStat console being installed, it creates a new user named vnstat in our system. This is the user that runs our vnstatd daemon and updates the database. You can see it by command below. See the most left column, that's the username: "vnstat".

$ ps aux | grep vnstat


The Problem


The problem is whether the database directory is owned by vnstat user or not. When it's not, of course vnstat console cannot update the traffic data unless we force it manually with sudo (or by root).

The Solution


Do chown to /var/lib/vnstat/ directory (where databases are stored) so it and its files re-owned by vnstat user.

$ sudo chmod -v -R vnstat:vnstat /var/lib/vnstat/


The Result


You should see that the vnstat/ directory itself, and all files inside it, are owned by same user "vnstat". See them by command below.

$ ls alR /var/lib/vnstat/


And both the vnstat console and vnStat PHP should now update the data automatically. Check your /etc/vnstat.conf file for the time delay between one and another updates.

References


http://askubuntu.com/questions/500663/vnstat-not-updating
http://serverfault.com/questions/350455/vnstat-only-updates-on-live