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 11092 times)

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Restarting DSLstats after power cut
« Reply #15 on: October 02, 2018, 01:12:50 PM »

A question: if you were to just mount it anyway, do you get an error status returned ? If so, then you would not need the pings, could just put the mount in your loop until it does not fail, or give up after n attempts to prevent infinite loop. Would that work?
Logged

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #16 on: October 02, 2018, 03:53:49 PM »

Initially I stored all snapshots etc in the default locations on the Pi, and manually transferred them to the NAS for long-term storage & review. However, I had a problem with the Pi that meant reflashing the SD card and I lost some data, so changed the auto-storage location to the NAS.
My NAS is a fairly old Seagate GoFlex Home device, which is set up for PC use, and mounting it when the Pi booted involved adding the path to the fstab file. That worked OK until a power cut meant that the Pi (& DSLstats) was up and running before the NAS was ready to mount. If I manually mounted the NAS after DSLstats was running, the save locations had already reverted to the default ones on the Pi.

It never occurred to me to put the mount command in the loop. It took me quite a while to get the syntax correct in the fstab file, and now it's working I'm somewhat reluctant to "fix what isn't broken". I don't see why it wouldn't work, but I know almost nothing about Linux, so don't take my word for it!

You have a good point about the infinite loop. I probably ought to include a counter so that after n attempts the Pi reverts to saving in the default locations.

I haven't managed to get the Webserver option working either, but I think that's because I am using a Pi Zero W, and the processor seems to be pretty well maxed out collecting stats and saving them to the NAS. I can post what I did for the Snapshots & DataStore if that would help.

Logged

tiffy

  • Kitizen
  • ****
  • Posts: 1319
Re: Restarting DSLstats after power cut
« Reply #17 on: October 02, 2018, 04:51:00 PM »

@Westie

Thanks for the reply.
I was using my old original RPi 1B running DSLStats until very recently, basically as it's not much good for anything else now, was really struggling, CPU virtually always @ 100% usage, never really recovered between samples.
Finally decided to pension off and now using my RPi 3B which as would be expected copes much better, CPU recovering quickly between samples.

Still running two RPi Zero W's on my sons & daughters lines (remotely monitored via VNC) which cope quite well and certainly don't appear to be running with CPU saturation for very long after sampling.

Eric (roseway) did try to help with the DSLStats, webserver issue but as the server was on my Win 8.1 desktop PC he thought this was the issue and as such was out of his domain, I did try running DSLStats on a RPi 3B+ at that time but it made no difference so don't think that your RPi Zero W usage is likely to be the root cause of the webserver problem.

My NAS is a 3Tb. WD My Cloud, I do have the availability of a 1Tb. HD on my desktop PC as I retained this for mass storage when upgrading the PC with a Samsung SSD for the operating system.

Would certainly appreciate the information you have offered ref. Snapshots & Data Store when you get the time.
Logged
BT FTTP 150/30, BT Smart Hub 2

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #18 on: October 02, 2018, 10:32:34 PM »

This is how I set up a Pi Zero W to save DSLstats Snapshots and DataStore to a NAS. It may not be the most elegant solution, but it works for me! I have removed personally identifying info, so you will need to modify where necessary to fit your situation.
Background Info: My NAS has a folder available to all registered users, named "GoFlex Home Public".

1. On the NAS, in "GoFlex Home Public" create a folder named "DSLstats", and within that create two further folders named "DataStore" and Snapshots" respectively.

2. On the Pi create a folder to act as the local mount point for the NAS.
Code: [Select]
mkdir /home/pi/NAS
3. Create a "Credentials" file
Code: [Select]
sudo nano /home/pi/.NAScredentialsThis file has only two lines:
Quote
username=yourusername
password=yourpassword
The items in bold should be changed to the appropriate ones registered on the NAS.

4. Change the file permissions:
Code: [Select]
sudo chmod 600 /home/pi/.NAScredentials
5. Modify the file /etc/fstab (after making a backup), by appending the following line
Code: [Select]
//192.168.xxx.xxx/GoFlex\040Home\040Public/DSLstats /home/pi/NAS cifs credentials=/home/pi/.NAScredentials,sec=ntlm,vers=1.0,rw,file_mode=0777,dir_mode=0777


6. Check that the NAS is mounted correctly by fstab
Code: [Select]
sudo mount -a
7. In DSLstats>Configuration>Snapshots, change the Snapshots directory to /home/pi/NAS/DSLstats/Snapshots

8.In DSLstats>Configuration>Data Store, change the location of the data store to /home/pi/NAS/DSLstats/DataStore

9. Reboot the Pi.

I hope this helps.

Edit: Removed wrong part of path in steps 7. & 8.
« Last Edit: October 03, 2018, 10:33:48 AM by Westie »
Logged

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #19 on: October 02, 2018, 11:23:32 PM »

. . . I've had to educate myself in Bash scripting (and other stuff!)

I've modified the dslstats.desktop file as recommended, . . .

I would like to offer a modification to your script --

#!/bin/bash

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

# Ping the NAS to check for its availability.
# If no response, wait 2 seconds (plus the ping timeout) then try again.
until ping -c1 192.168.xxx.xxx &> /dev/null; do
        sleep 2
done

# When NAS is available mount it.
sudo mount -a

# Then start DSLstats.
cd /home/pi/dslstats/
./dslstats

As Weaver has mentioned, you should consider adding a decrementing loop-count and aborting the attempted auto-start process if the NAS has not become available after N 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.

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #20 on: October 02, 2018, 11:40:34 PM »

Thanks, B*cat. That certainly looks more elegant!
Now I'm off back to the text books to find out what &> /dev/null means!

I'm getting "smarter every day"  :graduate:

Edit: And I will add a loop counter to cater for NAS failure!
« Last Edit: October 02, 2018, 11:43:31 PM by Westie »
Logged

burakkucat

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

Let me help by saying that the following two snippets are identical in effect . . .

some_command_producing_(unwanted)_output_on_the_stdout_and_stderr_streams &> /dev/null

some_command_producing_(unwanted)_output_on_the_stdout_and_stderr_streams > /dev/null 2>&1

The output produced by the ping command is unwanted, so send it to the null device. The standard output (stdout) stream, by default, has the descriptor number one. The standard error (stderr) stream, by default, has the descriptor number two.
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 #22 on: October 02, 2018, 11:58:44 PM »

Thanks, B*cat. That certainly looks more elegant!
Now I'm off back to the text books to find out what &> /dev/null means! Found it!

I'm getting "smarter every day"  :graduate:

Edit: And I will add a loop counter to cater for NAS failure!
Logged

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #23 on: October 03, 2018, 12:05:34 AM »

Let me help . . .

Thanks again. You are, as always, generous in your assistance.
Logged

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #24 on: October 03, 2018, 12:10:47 AM »

Thanks again. You are, as always, generous in your assistance.

  :blush:
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.

burakkucat

  • Respected
  • Senior Kitizen
  • *
  • Posts: 38300
  • Over the Rainbow Bridge
    • The ELRepo Project
Re: Restarting DSLstats after power cut
« Reply #25 on: October 03, 2018, 12:37:13 AM »

Another modification, to incorporate a loop-count --

#!/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 (plus 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--)) == 0 ] && exit
        sleep 2
done

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

# Then start DSLstats.
cd /home/pi/dslstats/
./dslstats
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 #26 on: October 03, 2018, 10:14:11 AM »

Thanks, B*cat, I'll use that.

[OT] Picking up Bash has been quite a steep learning curve for me. I last did "programming" with Fortran over 45 years ago, and it has been instructive to see how you achieve with one line of Bash using inbuilt commands what would have taken me several lines of messy code to replicate. I foresee several long winter nights of study ahead of me...[/OT]
Logged

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: Restarting DSLstats after power cut
« Reply #27 on: October 03, 2018, 10:19:54 AM »

Question from a Linux ignoramus:

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

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!
Logged
Broadband and Line rental: Zen Unlimited Fibre 2, Mobile: Vodaphone
Router: Fritz!Box 7530

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #28 on: October 03, 2018, 10:37:46 AM »

This is how I set up a Pi Zero W to save DSLstats Snapshots and DataStore to a NAS....

Oops! Just noticed I gave the wrong path in steps 7 & 8. Have edited the post to make correction.  :paperbag:
Logged

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #29 on: October 03, 2018, 12:48:01 PM »

Question from a Linux ignoramus:

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

Surely the mount should be in a loop and check for return code 0?
I suspect your knowledge of Linux far exceeds my own, and from a technical point of view you may well be right. However:
a) It may be that the NAS gets its IP address (& can thus respond to pings) after it has set up the other services required to perform its duties.
b) The script will only be of use in the case of a general power outage. If the Pi is restarted but the NAS left running the loop will not be invoked anyway.
c) If I put the router, Pi & NAS on a UPS the script becomes redundant, so the mount is still required in fstab.
d) mount -a looks a lot neater than the long line of code required for a full mount command  ;)

Quote
As a minimum, even if the mount isn't in the loop you should check for success before starting DSLstats!
Whilst that may be true for some people, it's not so for me. I only want to delay starting DSLstats until a slow-booting NAS is available. If the NAS fails completely I still want to start DSLstats, and save the stats data to the default locations on the Pi. I can always go back to manually transferring the data from the Pi if necessary.

I think the 'planned' power cut in a couple of days time will be quite instructive!
Logged
Pages: 1 [2] 3 4
 

anything