Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: 1 2 [3] 4

Author Topic: Restarting DSLstats after power cut  (Read 11087 times)

tiffy

  • Kitizen
  • ****
  • Posts: 1319
Re: Restarting DSLstats after power cut
« Reply #30 on: October 03, 2018, 05:47:58 PM »

@Westie

Belated thanks for your response, reply 18, will work through your instructions when I get sufficient time, much appreciated.
The later refinements offered by b*cat are more applicable to your power restoration issue, very informative, I should be OK as all devices are UPS powered. 
Logged
BT FTTP 150/30, BT Smart Hub 2

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #31 on: October 03, 2018, 07:16:02 PM »

If the service that responds to pings is running does that guarantee that the service to process the sudo mount will also be running?

The device which responds to the ping will be the NAS; the device which executes the mount command will be the R-Pi. If the R-Pi isn't running, how can the code be executed?  :D

Quote
Surely the mount should be in a loop and check for return code 0?

As a minimum, even if the mount isn't in the loop you should check for success before starting DSLstats!

No, for the mount command issued is not explicitly just for the NAS . . . there is the -a flag to consider and all that it implies.  ;)
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: Restarting DSLstats after power cut
« Reply #32 on: October 03, 2018, 09:43:55 PM »

But the r-Pi has to get a response from the NAS when the mount is executed. If the service which handles the mount request on the NAS doesn't come up before the r-PI surely the mount will fail. My NAS box takes several minutes to come up fully - I haven't checked how long it takes before Windows sees the shares which I assume accesses the same service that the mount will connect to (or a very closely related one). The problem here is that the r-Pi always comes up before the NAS.

I'd assume the standard boot of the r-Pi does a mount -a so doing a mount -a in this script feels very wrong to me. Surely it should be specifically mounting just the one resource it needs?
« Last Edit: October 03, 2018, 09:49:39 PM by jelv »
Logged
Broadband and Line rental: Zen Unlimited Fibre 2, Mobile: Vodaphone
Router: Fritz!Box 7530

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #33 on: October 03, 2018, 10:37:19 PM »

Here is a third version of the script --

#!/bin/bash

# A script to ensure that a slow-starting NAS is available before starting DSLstats.
# Requires /etc/fstab to be modified to include a line specifying the NAS mount point.

# Set a maximum loop count of 10.
let lc=10

# Ping the NAS to check for its availability.
# If no response, wait 2 seconds (after the ping timeout) then try again.
# Abort the process after 10 failed iterations of the loop.
until ping -c1 192.168.xxx.xxx &> /dev/null; do
        [ $((lc--)) -eq 0 ] && exit
        sleep 2
done

# The NAS is now available, so mount it.
sudo mount -a

# Check that the NAS is mounted.
if [ ! $(mount | grep -q NAS) ]; then
   # Now start DSLstats.
   cd /home/pi/dslstats/
   ./dslstats
fi


Changes/additions since version two are emboldened.
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #34 on: October 04, 2018, 12:54:56 AM »

Ideally the Pi should keep trying long enough to let the NAS come up, but not too much longer than that. The difficulty is that the time between the Pi coming up and the NAS being available is unknown.

For a loop count of 10 and a sleep time of 2 my Pi 3B+ takes approx 80 seconds to count down to zero. I'll run it again on Thursday with a loop count of 40, which should give the NAS about 5 minutes to come up. I suspect the Pi Zero W (which has a slower processor, and is the device I use for monitoring) will take somewhat longer, but I would be surprised if the NAS needs that length of time anyway. I may even put in a loop count of 100 and see how long that takes if I have the time!

On Friday after the power cut I should be able to compare the time difference between the modem starting and DSLstats starting, which would yield an approximate length of time for the NAS to come up. I can then adjust the loop count accordingly.
Logged

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #35 on: October 04, 2018, 01:17:04 AM »

There are two different times in one iteration of the loop; the time-out time of a ping to a non-responsive device and the explicit period to sleep.

[Duo2 tmp]$ time ping -c1 192.168.0.2 &> /dev/null

real   0m3.006s
user   0m0.000s
sys    0m0.001s
[Duo2 tmp]$

Attempting to ping a non-existent device takes about three seconds.

#!/bin/bash

let lc=10

until ping -c1 192.168.0.2 &> /dev/null; do
        [ $((lc--)) -eq 0 ] && exit
        sleep 2
done

Timing the execution of the above test script shows --

[Duo2 tmp]$ time zxc

real   0m53.088s
user   0m0.007s
sys    0m0.013s
[Duo2 tmp]$

You might prefer to increase the sleep time rather than the number of iterations of the loop?  :-\
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: Restarting DSLstats after power cut
« Reply #36 on: October 04, 2018, 07:54:59 AM »

The unfortunate thing with all of this is that not only will the Pi and NAS have rebooted but the router will have done so as well and that will probably have come up quicker than the others. The result of that is that router stats from immediately it connects won't be collected which could be useful.
Logged
Broadband and Line rental: Zen Unlimited Fibre 2, Mobile: Vodaphone
Router: Fritz!Box 7530

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #37 on: October 04, 2018, 05:42:10 PM »

The unfortunate thing with all of this is that not only will the Pi and NAS have rebooted but the router will have done so as well and that will probably have come up quicker than the others. The result of that is that router stats from immediately it connects won't be collected which could be useful.

Indeed so. But I think it is worthwhile that all avenues are explored by the OP . . . as that, in my experience, is how somebody learns and not by being told "this, that & the other" with a stream of criticism.  :-\

[Edited to correct a typo.]
« Last Edit: October 05, 2018, 05:35:22 PM by burakkucat »
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #38 on: October 04, 2018, 09:14:52 PM »

... router stats from immediately it connects won't be collected which could be useful.
That's true, but on the other hand they will be stored in a consistent place, which could be equally useful.
Logged

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #39 on: October 05, 2018, 09:50:29 AM »

OK, the results are in...& it works! :thumbs:

I'm not sure how easy it will be to figure out the exact time that each piece of equipment completed its start sequence. The modem & router are in one room, and the NAS & Pi are in another, and because the Pi has no on-board battery the times reported by DSLstats are wrong by several minutes until the Pi picks up the network time server.

However, I don't really mind. The data is being saved on the NAS...which was the primary aim of the project.  :) If I really want to know the detail of what is happening in the first few minutes of the modem starting I'll keep the monitoring equipment running throughout. But right now I have other priorities.

Thanks everyone for your help.

George
Logged

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #40 on: October 05, 2018, 05:38:21 PM »

OK, the results are in...& it works! :thumbs:

That is good to know. Thank you for reporting back.

Quote
Thanks everyone for your help.

You are welcome.  :)
Logged
:cat:  100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Please consider making a donation to support the running of this site.

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: Restarting DSLstats after power cut
« Reply #41 on: October 05, 2018, 06:57:12 PM »

Excellent :)
Logged
  Eric

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Restarting DSLstats after power cut
« Reply #42 on: October 11, 2018, 11:29:05 AM »

Would this be any good?

let lc=10
until [ $((lc--)) == 0 ] || ping -c 1 -w 1 -W 1  192.168.0.2  ; do
    sleep 1
done
Logged

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #43 on: October 12, 2018, 01:14:52 PM »

I don't know, and I am rather reluctant to try.

I am using the script B*cat proposed in reply #25, with a loop count of 40 and the "exit" command changed to "break". (Otherwise the Pi just hangs if the NAS is unavailable.)

Another power cut this morning (thank you storm Callum) demonstrated that what I use works, so I have no reason to change things.
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Restarting DSLstats after power cut
« Reply #44 on: October 16, 2018, 04:10:08 AM »

Indeed, what you have works, so all good.

It was just a question to further my understanding - an alternative that is a little more compact and, I think, readable.

I will test it, and perhaps our good friend Burakkucat might check my homework for us?
Logged
Pages: 1 2 [3] 4