Bug 277507 - net/ntopng: rc.d startup script missing redis requirement
Summary: net/ntopng: rc.d startup script missing redis requirement
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Guido Falsi
URL:
Keywords: easy, needs-patch, needs-qa
Depends on:
Blocks:
 
Reported: 2024-03-05 16:59 UTC by tobias@gion.io
Modified: 2024-03-08 10:38 UTC (History)
0 users

See Also:
madpilot: maintainer-feedback+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tobias@gion.io 2024-03-05 16:59:38 UTC

    
Comment 1 tobias@gion.io 2024-03-05 17:19:24 UTC
Expected behavior
-----------------

ntopng service should be started AFTER the redis service (same machine).

Observed behavior
-----------------

ntopng starts before the redis service and therefore exits with an error:
05/Mar/2024 18:09:05 [Redis.cpp:98] ERROR: Connection error [Connection refused]
05/Mar/2024 18:09:06 [Redis.cpp:153] ERROR: ntopng requires redis server to be up and running
05/Mar/2024 18:09:06 [Redis.cpp:154] ERROR: Please start it and try again or use -r
05/Mar/2024 18:09:06 [Redis.cpp:157] ERROR: to specify a redis server other than the default
/usr/local/etc/rc.d/ntopng: WARNING: failed to start ntopng

rcorder shows ntopng severals service before redis:
rcorder /etc/rc.d/* /usr/local/etc/rc.d/*

How to reproduce
----------------

1. Install ntopng and follow pkg-message
2. Setup local redis server
3. Enable redis and ntopng in rc.conf
4. Reboot

Depending on how many other services are started, ntopng service will fail if the redis service is not up and running in time.

Fix
---

Change /usr/local/etc/rc.d/ntopng:

< # REQUIRE: LOGIN netif mysql
---
> # REQUIRE: LOGIN netif mysql redis

I am aware that it is possible (and probably common) to have a redis instance on another machine and this solution would be obsolete. What do you think?
Comment 2 Guido Falsi freebsd_committer freebsd_triage 2024-03-05 18:08:06 UTC
This is a difficult issue to properly fix.

Blindly adding redis to REQUIRES would cause warnings in rcorder when redis is not installed on the machine (because one is using redis on another machine). This is not critical but also not optimal.

Ports don't provide tools for such details. I could say that, this being a sysadmin tool, users are expected to know what they are doing and adapt the startup scripts.

On the other hand, adding redis blindly would not break anything; only cause warnings, so it would be doable although unelegant.

Not sure what the best choice would be, I need to think about this a little.

Give me some time to check what other ports are doing and evaluate things.
Comment 3 Guido Falsi freebsd_committer freebsd_triage 2024-03-08 10:20:36 UTC
Again thanks for reporting the issue. I would have not acted on this if you didn't.

I now think your suggestion is correct. Adding the require when redis is not installed only causes an unharmful warning:

rcorder: requirement `redis' in file `/usr/local/etc/rc.d/ntopng' has no providers.

if redis happens to be installed but not enabled not even the warning is issued.

So no hard in putting it there, and it would solve a real ordering issue.

BTW I also forgot the script already contains a requirement on "mysql" which could also not be present or disabled.

I'll commit the change shortly together with an update to the ports.

Thanks again!
Comment 4 tobias@gion.io 2024-03-08 10:35:01 UTC
No, thank you Guido for your consideration and effort.

I also found a mention about this conflict at the end of the rcorder manpage:

       The `REQUIRE' keyword is	misleading: It does not	describe which daemons
       have to be running before a script will be started.  It describes which
       scripts must be placed before it	in the dependency ordering.  For exam-
       ple, if your script has a `REQUIRE' on `sshd', it means the script must
       be placed after the `sshd' script in the	dependency ordering, not  nec-
       essarily	that it	requires sshd to be started or enabled.

Thanks again for your time and take care!
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-03-08 10:35:05 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a08874f9512bd092dee697036af2e11c3f7dd806

commit a08874f9512bd092dee697036af2e11c3f7dd806
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2024-03-08 10:33:57 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2024-03-08 10:33:57 +0000

    net/ntopng: Update to latest upstream commit, improve rc script.

    ntopng needs to start after redis. Add a redis REQUIRE to the rc
    script to make sure the correct order is applied.

    PR:     277507

 net/ntopng/Makefile        | 5 ++---
 net/ntopng/distinfo        | 6 +++---
 net/ntopng/files/ntopng.in | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)
Comment 6 Guido Falsi freebsd_committer freebsd_triage 2024-03-08 10:38:16 UTC
Requirement added to rc script.