ntop / ntopng

Web-based Traffic and Security Network Traffic Monitoring
http://www.ntop.org
GNU General Public License v3.0
6.18k stars 648 forks source link

ntopng doesnt auto start properly on boot on raspberry pi #532

Closed techmad closed 8 years ago

techmad commented 8 years ago

I found ntopng does not stay started after reboot on Rasberry Pi. I think because no hardware clock.

Apr 24 02:18:56 pi systemd[1]: Started LSB: Start/stop ntopng web.
Apr 24 02:18:56 pi ntopng: [Lua.cpp:4484] WARNING: Script failure [/usr/share/ntopng/scripts/callbacks/second.lua][/usr/share/ntopng/scripts/lua/modules/graph_utils.lua:854: /var/tmp/ntopng/3/rrd/bytes.rrd: illegal attempt to update using time 1461464336 when last update time is 1461464644 (minimum one second step)]
Apr 24 02:18:57 pi ntopng: [Lua.cpp:4484] WARNING: Script failure [/usr/share/ntopng/scripts/callbacks/second.lua][/usr/share/ntopng/scripts/lua/modules/graph_utils.lua:854: /var/tmp/ntopng/3/rrd/bytes.rrd: illegal attempt to update using time 1461464337 when last update time is 1461464644 (minimum one second step)]
Apr 24 02:18:58 pi ntopng: [Lua.cpp:4484] WARNING: Script failure [/usr/share/ntopng/scripts/callbacks/second.lua][/usr/share/ntopng/scripts/lua/modules/graph_utils.lua:854: /var/tmp/ntopng/3/rrd/bytes.rrd: illegal attempt to update using time 1461464338 when last update time is 1461464644 (minimum one second step)]
..
Apr 24 02:31:07 cognitive systemd[1]: Time has been changed

Because Rasberry doesn't come with hardward clock by default, it takes a while for NTP to come into sync from factory default old date. Firstly the RRD inserts fails being earlier than last update (before boot) as seen above.

But it seams ntopg process also stops also when the time gets updated on the fly, but I cant confirm different logs.

I think I solved my issue adding ntp-wait to /etc/init.d/ntopng

case "$1" in
  start)
        ntp-wait;      <--------
        start_ntopng 0;
        ;;

Just posting this for comment if this is the right approach.

Need to check too if init.d parallel processes on Rasberry pi, else the above could be holding up other processes starting??

techmad commented 8 years ago

Nope.. didn't work.. Just hangs the startup process now after reboot..

root@pi:/home/pi# ps -ef | grep ntopng
root       497     1  0 03:20 ?        00:00:00 /bin/bash /etc/init.d/ntopng start
root      2155  2124  0 03:21 pts/0    00:00:00 grep ntopng
root@pi:/home/pi# date
Sun 24 Apr 03:21:16 UTC 2016
root@pi:/home/pi# /bin/bash /etc/init.d/ntopng start
[....] Starting ntopng (via systemctl): ntopng.service
<hangs>

I know this is more of a Raspberry pi / debian issue to resolve, but since ntopng officially supported on ARM, and ntopng controls the init.d script source, any suggestions??

I have licensed copy, and used ntopng shop install instructions.

lucaderi commented 8 years ago

I assume that you have set the time before starting ntopng, and thus I do not believe this is a ntopng issue. If you have a patch for Raspberry please share it with us via a pull request.

techmad commented 8 years ago

Raspberry does have hardware clock, unless you buy/add module. So it’s not a matter of just ‘setting the time’ once. Raspberry Pi basically gets it correct time on every boot from NTP

Your init script starts ntopng embedded version straight away… which a) starts to fails RRD updates since time insert is before last update time of RRD file. Those errors are fine, until clock gets updated, but b) it seems ntop stops/crashes when the time gets updated after ntopng has started – and nothing in any logs to reason why.

In other words, out of the box after installing and running embedded version on factory Raspberry Pi (Jessie) - ntopng never successfully auto starts (or stays started) after a reboot. This impacts where I also use the ntopng bridged modes to employ filtering, which case the site goes offline until manually restarted.

It is an ntopng embedded/ARM ntog init.d script oversight/issue, as this package/licenced version is geared to raspberry pi without hardware clock. Surprised this not ever raised before. It means ntopng needs manual start or some customer delayed script when using your licenced package.

No worries, if I find a patch working for myself with ntopng init.d script, or custom boot startup script. I will share results via blog/issues git to help others. I am not fulltime developer to do pull request. I perfectly understand where your focus need to go. I do really like your product and followed the open source version a long time.

Curious - if I had raised this within the 5 days support windows (I purchased this ~10 days ago) would it have been looked at as an issue you would helped fix?

Cheers,

Jason

lucaderi commented 8 years ago

This is a bug and it must be fixed regardless of the installation support time window. Now I understand the problem after your second explanation. Let me see what I can do. Stay tuned.

techmad commented 8 years ago

Great! For reference it was a clean install Raspbian - Jessie Lite - 2016-03-18 Kernel 4.1 Stock install as per: http://packages.ntop.org/RaspberryPI/

Hopefully it can be replicated by simple reboot. ntopng crashes I think when NTP updates.

In case not replicated, from stock ntopng install I added only this to config:

-i=bridge:eth1,eth2 -m="10.0.0.0/8" -F="mysql;localhost;ntopng;flows;root;xxxx"

Perhaps only enabling bridge or msyql replicates the issue, I have not tried yet to disable then reboot.

techmad commented 8 years ago

Ok, this is strange. I removed MYSQL and bridge and ntopng started OK after reboot. I then put back config back in and ntopng seams to have started (twice tested) without crash.

Sorry, maybe this is not a bug after all. Maybe in my other failures (tested multiple times over one hour) the debian default NTP servers had more a delayed response getting time perhaps. But it appears to be rebooting just fine and ntopng does not stop after auto init.d start script

lucaderi commented 8 years ago

Closed. Will be reopen if necessary. Thanks for reporting it.

techmad commented 8 years ago

Hi, I tried to simulate the same problem by disabling internet to delay NTP during boot. I could not replicate issue. I see Raspberry Pi still has current and correct date even without NTP internet. Which I don't understand since there is no hwclock.

pi@raspberry:~ $ hwclock
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.

I did however install ntpdate when trying to fix the issue before using 'ntp-wait'

pi@raspberry:~ $ tail /var/log/apt/history.log -n 5

Start-Date: 2016-04-24  03:38:36
Commandline: apt-get install ntpdate
Install: lockfile-progs:armhf (0.1.17, automatic), ntpdate:armhf (4.2.6.p5+dfsg-7+deb8u1)
End-Date: 2016-04-24  03:38:43

Perhaps close this bug for now until someone else gets the same issue. Sorry for the trouble.

Cheers,

Jason

anubisg1 commented 7 years ago

i have the exact same issue. Ntop won't start at boot even if is configured to do so.

anubisg1 commented 7 years ago
root@dns1 /etc/init.d # systemctl status ntopng.service
● ntopng.service - Start/stop ntopng program
   Loaded: loaded (/etc/systemd/system/ntopng.service; enabled)
   Active: failed (Result: exit-code) since Tue 2017-01-03 10:21:36 CET; 2min 24s ago
  Process: 520 ExecStart=/etc/init.d/ntopng start (code=exited, status=99)

Jan 03 10:21:34 dns1 systemd[1]: Starting Start/stop ntopng program...
Jan 03 10:21:34 dns1 logger[588]: ntopng start
Jan 03 10:21:35 dns1 ntopng[520]: Starting ntopng:ntopng already running. Quitting ... failed!
Jan 03 10:21:35 dns1 ntopng[520]: failed!
Jan 03 10:21:36 dns1 systemd[1]: ntopng.service: control process exited, code=exited status=99
Jan 03 10:21:36 dns1 systemd[1]: Failed to start Start/stop ntopng program.
Jan 03 10:21:36 dns1 systemd[1]: Unit ntopng.service entered failed state.
anubisg1 commented 7 years ago

It seems that when you install ntopng, ntopng and redis-servers get added into the start-up process (rc.d) at the same level of priority, and ntopng requires redis-server to start first.

chanign this line:

# Required-Start:    $local_fs $remote_fs $network $syslog $pf_ring

to this:

# Required-Start:    $local_fs $remote_fs $network $syslog $pf_ring $redis-server

fixed it for me it seems

anubisg1 commented 7 years ago

false alarm, it didn't work on 2nd reboot