Bug 246160

Summary: net-mgmt/librenms: fix log file creation in rc script
Product: Ports & Packages Reporter: Dries Michiels <driesm>
Component: Individual Port(s)Assignee: Dan Langille <dvl>
Status: Closed FIXED    
Severity: Affects Only Me CC: moiseev
Priority: --- Flags: bugzilla: maintainer-feedback? (dvl)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
librenms.diff
none
librenmsv2.diff none

Description Dries Michiels freebsd_committer freebsd_triage 2020-05-04 07:02:52 UTC
Created attachment 214088 [details]
librenms.diff

I missed /dev/null in my previous checks for the logfile creation, now we actually tell it to copy something to the location intended. Pointyhat => Me :-)
Comment 1 Dries Michiels freebsd_committer freebsd_triage 2020-05-04 09:13:44 UTC
Created attachment 214100 [details]
librenmsv2.diff

Also disable allowance of multiple instances.
When the -m flag is specified I had the following error:

Traceback (most recent call last):
  File "/usr/local/www/librenms/librenms-service.py", line 48, in <module>
    service.start()
  File "/usr/local/www/librenms/LibreNMS/service.py", line 232, in start
    self.check_single_instance()  # don't allow more than one service at a time
  File "/usr/local/www/librenms/LibreNMS/service.py", line 494, in check_single_instance
    self._fp = open(lock_file, 'w')  # keep a reference so the file handle isn't garbage collected
PermissionError: [Errno 13] Permission denied: '/usr/local/www/librenms/.lock.service'

The service tries to write a lock file in the /usr/local/www/librenms dir, where it does not currently have the permissions for (owner is root:wheel). Solution: Either change ownership of the dir to www:wheel, or remove the -m flag in the service command.

The latter is proposed as librenms_flags="-m" can always be specified by the user to append it to the command args.
Comment 2 Dries Michiels freebsd_committer freebsd_triage 2020-05-04 09:27:05 UTC
The dispatching service is now running happily on my system. :-)
Comment 3 Dan Langille freebsd_committer freebsd_triage 2020-05-04 13:49:29 UTC
(In reply to Dries Michiels from comment #1)

How did you get this error message? I cannot reproduce it.
Comment 4 Dries Michiels freebsd_committer freebsd_triage 2020-05-04 13:53:37 UTC
What permissions do you have on /usr/local/www/librenms?
Mine are at stock created from the port @ 755 with root:wheel ownership.
Meaning that www user cannot create files in that directory and thus also not the daemon. The port creates it that way with a fresh install. I believe that if you manually have set permissions at one point in time they will have been retained even when upgrading librenms through the years.
Comment 5 Dan Langille freebsd_committer freebsd_triage 2020-05-04 14:41:58 UTC
(In reply to Dries Michiels from comment #4)

I have [dan@besser:~] $ ls -ld /usr/local/www/librenms
drwxr-xr-x  23 www  www  66 May  3 18:15 /usr/local/www/librenms

That explains that.

I deinstalled the package, and moved that directory aside. It had many lingering items. I think there are more things in there which need to be in /var/db/ or /var/log

Post new-install, I have:

$ ls -ld /usr/local/www/librenms
drwxr-xr-x  22 root  wheel  60 May  4 14:38 /usr/local/www/librenms

Here is what I had leftover in that directory:

[dan@besser:/usr/local/www/librenms.2020-05-04] $ ls -l
total 971
drwxr-xr-x   4 root  www        5 May  4 14:36 LibreNMS
drwxr-xr-x   3 root  www        3 May  4 14:36 bootstrap
-rwxr-xr-x   1 root  www  1969526 Mar 19 18:57 composer.phar
lrwxr-xr-x   1 root  www       34 Mar  3 14:23 config.php -> /usr/local/etc/librenms-config.php
drwxr-xr-x   2 root  www        5 May  4 14:36 includes
drwxrwxr-x   2 www   www        3 Oct 24  2018 logs
drwxrwxr-x   3 www   www        3 May  4 14:36 storage
drwxr-xr-x  10 root  www       10 May  4 14:36 vendor

I'll have a sniff around there.

As you can see, I put my config elsewhere. I'd like that to eventually be what the port does.
Comment 6 Dries Michiels freebsd_committer freebsd_triage 2020-05-04 14:47:11 UTC
Are you able to reproduce now? Also, I am in full favor to support hier(7) for file locations, i.e. /usr/local/etc/ for config files. I noticed the same lingering things a while back when I did a fresh install of LibreNMS :O!
Comment 7 Dan Langille freebsd_committer freebsd_triage 2020-05-04 15:16:03 UTC
(In reply to Dan Langille from comment #5)
FYI, I was able to reproduce your error message.
Comment 8 Dan Langille freebsd_committer freebsd_triage 2020-05-04 15:59:48 UTC
I'm getting double logging.  I'll look into that later.

*** /var/log/librenms/librenms-service.log ***
Alerting(INFO):Checking alerts
Billing(INFO):Calculating billing
Alerting(INFO):Completed alerting run for alerts in 0.27s
Billing(INFO):Completed billing run for calculate in 0.25s

*** /var/log/messages ***
May  4 15:58:00 besser librenms[32831]: Alerting(INFO):Checking alerts
May  4 15:58:00 besser librenms[32831]: Billing(INFO):Calculating billing
May  4 15:58:00 besser librenms[32831]: Alerting(INFO):Completed alerting run for alerts in 0.27s
May  4 15:58:00 besser librenms[32831]: Billing(INFO):Completed billing run for calculate in 0.25s
Comment 9 Dan Langille freebsd_committer freebsd_triage 2020-05-04 19:05:21 UTC
For future consideration, these directories in /usr/local/www/librenms are bing updated by the application. They should be moved outside WWWDIR

storage - seems to be a caching directory - should be in /var/db/librenms/storage
logs - should by in /var/log/librenms but with a different name perhap
s?
bootstrap/cache - should be in /var/db/librenms/cache

The existing /var/log/librenms/librenms.log should be named poller.log
Comment 10 Dan Langille freebsd_committer freebsd_triage 2020-05-05 14:45:40 UTC
In the meantime, we have a break. I'll commit that fix now.
Comment 11 commit-hook freebsd_committer freebsd_triage 2020-05-05 15:22:59 UTC
A commit references this bug:

Author: dvl
Date: Tue May  5 15:22:17 UTC 2020
New revision: 534092
URL: https://svnweb.freebsd.org/changeset/ports/534092

Log:
  fix log file creation in rc script

  disable allowance of multiple instances (-m in rc.d script)

  PR:		246160
  Submitted by:	Dries Michiels <driesm.michiels@gmail.com>

Changes:
  head/net-mgmt/librenms/Makefile
  head/net-mgmt/librenms/files/librenms.in
Comment 12 Dan Langille freebsd_committer freebsd_triage 2020-05-05 15:28:55 UTC
Thank you Mark, well done.
Comment 13 Dan Langille freebsd_committer freebsd_triage 2020-05-07 16:04:56 UTC
(In reply to Dan Langille from comment #9)

Also: config.php should be in /usr/local/etc/librenms/
Comment 14 Dan Langille freebsd_committer freebsd_triage 2020-05-09 01:29:40 UTC
(In reply to Dan Langille from comment #8)

That double logging is fixed by removing '-T $name ' from the rc.d script
Comment 15 Dries Michiels freebsd_committer freebsd_triage 2020-05-09 08:09:58 UTC
hehe, good catch, -T probably implies syslog logging because we explicitly specify its syslog tag.
Comment 16 Dan Langille freebsd_committer freebsd_triage 2020-05-09 15:24:13 UTC
This is what I use now for logging because it gets us timestamps:

command_args="-T $name -l local3 -p $pidfile /usr/local/www/librenms/librenms-service.py"


This in /etc/syslog.conf:

*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err;local3.none	/var/log/messages


This in /usr/local/etc/syslog.d/librenms.conf 
# this is a file for syslog.conf
# it should be installed to /usr/local/etc/syslog.d

local3.*		/var/log/librenms/librenms-service.log
Comment 17 Alexander Moisseev 2020-05-20 07:40:47 UTC
(In reply to Dan Langille from comment #14)

> That double logging is fixed by removing '-T $name ' from the rc.d script

Would you fix it for the rest of us please?

For instance, if some one needs syslog logging we could introduce an rc.d flag.
Simply removing '-T' option is also fine.

In my opinion, port shouldn't log to two destination simultaneously out of the box, moreover it shouldn't flood /var/log/messages at 'inform' level (LibreNMS default).
Comment 18 Dries Michiels freebsd_committer freebsd_triage 2020-05-20 09:37:17 UTC
I will make a patch tonight in a new PR. I'll CC you.