Kitz Forum

Broadband Related => Router Monitoring Software => Topic started by: Westie on September 22, 2018, 10:09:37 PM

Title: Restarting DSLstats after power cut
Post by: Westie on September 22, 2018, 10:09:37 PM
A plea for help from a Linux noob  :baby:

For several months I have monitored my DSL connection using DSLstats on a Raspberyy Pi Zero W. Thanks to an excellent dsl.desktop file from roseway the program runs from boot.
I have recently started to save the data to a NAS on my LAN by modifying /etc/fstab to mount the NAS when the Pi boots, and changing the Snapshots and DataStore locations in DSLstats appropriately. Both the Pi and the NAS are allocated fixed IP addresses by the router.

So far so good...until we have a power cut!

When the power comes back on, the modem/router and Pi boot up OK, but the NAS seems to be a little slower, and is unavailable when fstab runs on the Pi. Consequently DSLstats reverts to the default locations for Snapshots and DataStore.
Ideally I want the Pi to wait, and not try to mount the NAS until it is available, or run DSLstats until the NAS is mounted.

I have searched for answers on t'internet, but cannot find anything relevant to Raspbian Stretch. (Maybe I need to refine my searching skills!) Advice varies between using a bash script...python...systemd...cron...rc.local all of which are new to me, and some of which seem to contradict!

Can anyone help, or point me in the right direction? Thanks.
Title: Re: Restarting DSLstats after power cut
Post by: Deathstar on September 22, 2018, 10:15:11 PM
Do you use a start up script? If so use the sleep command.
Could be an option?
Title: Re: Restarting DSLstats after power cut
Post by: Westie on September 22, 2018, 10:33:24 PM
DSLstats is invoked by a script (I think) called dslstats.desktop in /home/pi/.config/autostart.

The problem seems to be that /etc/fstab tries to mount the NAS before it is ready, because if the NAS is already running when the pi is powered on there is no problem.

Can I add a sleep command to fstab?
Title: Re: Restarting DSLstats after power cut
Post by: Weaver on September 23, 2018, 03:58:47 AM
Cron? With a delta time? I am not sure how to schedule something at ‘now + n secs’, have done it on winnt with the ‘at’ command.
Title: Re: Restarting DSLstats after power cut
Post by: roseway on September 23, 2018, 07:49:39 AM
dslstats.desktop isn't a script, it's a desktop shortcut, as commonly used in Linux systems to launch programs. I'm not sure if there's a way to put a delay into the program launch, but one indirect way would be:-

Write a simple script to launch DSLstats, something like this:

Code: [Select]
#!/bin/sh
sleep 5
cd <path to DSLstats directory>
./dslstats

Save this script as launch-dslstats in the same directory as dslstats.desktop and make it executable.

Then edit dslstats.desktop and change the Exec line to

Code: [Select]
Exec=/home/pi/.config/autostart/launch-dslstats
This would give a 5 second delay before starting DSLstats. Change the sleep line in the script as required for a different delay - the value is in seconds.
Title: Re: Restarting DSLstats after power cut
Post by: Westie on September 23, 2018, 04:07:21 PM
dslstats.desktop isn't a script, it's a desktop shortcut, as commonly used in Linux systems to launch programs.

Thanks for the correction: my mistake shows how little I know of Linux.

However, I don't think the problem is (only) with the speed at which DSLstats starts. The main issue is that the NAS isn't mounted at all, so however long I delay the DSLstats launch it will still revert to the default locations for Snapshots and DataStore.

Would it work if I modified the script to:
Code: [Select]
#!/bin/sh
sleep 5
mount -a
cd <path to DSLstats directory>
./dslstats

Edit: I know the fstab file works, as everything runs as expected if the NAS is running before the Pi is powered up.
Title: Re: Restarting DSLstats after power cut
Post by: roseway on September 23, 2018, 04:41:45 PM
That should work, but you would need to edit fstab so as to allow the ordinary user to mount the NAS device. In the relevant line there will be a list of mount options near the end of the line, starting with 'defaults' and maybe other things separated by commas. You need to add ',user' at the end of this part (with no spaces). So if the line says:

******  *******  ******  defaults,rw  0  0

then change it to read

******  *******  ******  defaults,rw,user  0  0
Title: Re: Restarting DSLstats after power cut
Post by: Westie on September 24, 2018, 09:57:58 AM
Thanks for that, Eric.

I have amended the script accordingly, but I am rather reluctant to try it out because I don't like 'pulling the plug' on running systems more than necessary, and doing an orderly shutdown/startup doesn't really reflect what happens with a power cut.

Maybe I'll just wait for the next power outage, and make a mental note to see what happens. In the meantime I'll try to educate myself about Linux and Bash scripting.
Title: Re: Restarting DSLstats after power cut
Post by: jelv on September 24, 2018, 10:11:28 AM
I'd suggest you try an orderly restart. If that doesn't work it sure as hell won't work after a power fail. If it does work there's a way better than average chance it will work after a power fail.
Title: Re: Restarting DSLstats after power cut
Post by: jelv on September 24, 2018, 10:15:56 AM
Any reason why you haven't looked at putting the router and Pi on a UPS? Even the smallest one would keep them running for a long time. If you have a cordless phone you could put the base station on as well.
Title: Re: Restarting DSLstats after power cut
Post by: Westie on September 24, 2018, 01:47:21 PM
I'll look into that. Right now, though, we are packing up for an imminent house move (hopefully in the next few weeks), so we are going through the process of de-cluttering, rather than adding extra equipment.

Sounds like a project for the new place... ;)
Title: Re: Restarting DSLstats after power cut
Post by: Weaver on September 25, 2018, 04:16:32 AM
Would sudo mount -a help? (Apol if I am missing the point here.)
Title: Re: Restarting DSLstats after power cut
Post by: roseway on September 25, 2018, 07:07:07 AM
Yes, you're right - the way sudo is set up on the RPi, it doesn't need the user to enter a password. I didn't think of that. So it shouldn't be necessary to edit fstab.
Title: Re: Restarting DSLstats after power cut
Post by: Westie on October 02, 2018, 10:29:49 AM
Thanks for all the help; especially @roseway and @Weaver. Sorry for the delay in replying, but I've had to educate myself in Bash scripting (and other stuff!)

I've modified the dslstats.desktop file as recommended, and created the following script
Code: [Select]
#!/bin/bash
# A script to ensure a slow-starting  NAS is running before starting DSLstats
# Requires /etc/fstab to be modified to include path to NAS

# Ping NAS to check if available
ping -c1 192.168.xxx.xxx

# If no response, wait 2 seconds then try again
while [ $? = 1 ]
 do
  sleep 2
  ping -c1 192.168.xxx.xxx
done

# When NAS is available mount it
sudo mount -a

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

(The many comment lines are to remind me what I've done next time I look at it!)

I've tested the script on a spare Pi running a non-sampling instance of DSLstats, using my phone as a stand-in for the NAS, and it appears to work OK. There is a planned power cut in 3 days time (probably to replace the faulty equipment that caused the last outage), so I won't have to wait long to see if everything is as it should be.

I'll report the result - as much for my own record as anything.
Title: Re: Restarting DSLstats after power cut
Post by: tiffy on October 02, 2018, 11:57:39 AM
@Westie

Following this thread with interest, well done, you appear to have achieved a workable solution.

I am running my router, RPI, Win desktop PC  & NAS on a 1000 VA UPS so would not have this issue, however, it has occured to me that I am still storing my DSLStats saved snapshot files on the RPi and manually transferring to desktop PC/NAS to archieve, have never managed to get the DSLStats Datastore/Webserver options working on Windows.

Your method of mounting the NAS on the RPi would seem a more sensible option, could I ask for a quick idiots guide as to how I would achieve this ?
Title: Re: Restarting DSLstats after power cut
Post by: Weaver 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?
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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.

Title: Re: Restarting DSLstats after power cut
Post by: tiffy 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.
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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.
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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!
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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!
Title: Re: Restarting DSLstats after power cut
Post by: Westie on October 03, 2018, 12:05:34 AM
Let me help . . .

Thanks again. You are, as always, generous in your assistance.
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat on October 03, 2018, 12:10:47 AM
Thanks again. You are, as always, generous in your assistance.

  :blush:
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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]
Title: Re: Restarting DSLstats after power cut
Post by: jelv 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!
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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:
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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!
Title: Re: Restarting DSLstats after power cut
Post by: tiffy 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. 
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.  ;)
Title: Re: Restarting DSLstats after power cut
Post by: jelv 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?
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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.
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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?  :-\
Title: Re: Restarting DSLstats after power cut
Post by: jelv 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.
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.]
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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.
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat 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.  :)
Title: Re: Restarting DSLstats after power cut
Post by: roseway on October 05, 2018, 06:57:12 PM
Excellent :)
Title: Re: Restarting DSLstats after power cut
Post by: Weaver 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
Title: Re: Restarting DSLstats after power cut
Post by: Westie 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.
Title: Re: Restarting DSLstats after power cut
Post by: Weaver 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?
Title: Re: Restarting DSLstats after power cut
Post by: burakkucat on October 16, 2018, 03:30:22 PM
. . . perhaps our good friend Burakkucat might check my homework for us?

The logic is good. Setting a ping timeout removes the wait at that point in the code. I would suggest a longer sleep period than one second . . . it really depends upon how slowly the NAS boots and subsequently becomes ready. As a starting point, I would probably sleep for 30 seconds. Another small point to consider is what should be the default action if the NAS never becomes ready? I.e. The countdown has reached zero?
Title: Re: Restarting DSLstats after power cut
Post by: Weaver on October 16, 2018, 08:00:16 PM
Learning old sh and bash right now, I am getting mixed up with all the syntax, the single square bracket trick versus the new(?) [[ ]] technology and the (( )) round bracketed evaluation syntax. It is all quite a mixture.
Title: Re: Restarting DSLstats after power cut
Post by: Westie on October 17, 2018, 12:10:49 AM
Another small point to consider is what should be the default action if the NAS never becomes ready? I.e. The countdown has reached zero?
In my case I wanted DSLstats to start anyway, which is why I changed exit to break, so the rest of the script runs. If the NAS is never ready I think it's better to collect data in the default location on the Pi than lose it altogether.
Title: Re: Restarting DSLstats after power cut
Post by: tiffy on October 28, 2018, 12:12:15 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: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.

Many thanks to Westie for posting this detailed explanation ref. mounting a Windows folder on a RPI.

However, I am still struggling with the command line format within the /etc/fstab file, keep getting a syntax error from the added command line when running the "sudo mount -a" command, won't mount.
Have tried many possible permutations of the command including configuring guest access to eliminate any possible username or password issues, guidance found here:
https://wiki.ubuntu.com/MountWindowsSharesPermanently

My NAS setup is:
WDMyCloud, 192.168.0.**, \Public\DSLStats\DataStore & Snapshots
Not aware that the NAS has any password requirement, assuming that the username is WDMyCloud (or use IP address)

The final objective of the exercise is to get DSLStats web upload facilities working to my NAS or Win PC hard disk which is not possible at present.

Any suggestions appreciated.
 
Title: Re: Restarting DSLstats after power cut
Post by: Westie on October 28, 2018, 10:46:17 PM
As a Linux newbie it also took me a lot of trial and error to get a mount command line that worked!

Most of the results of my searches were for different distros and couldn't be relied on - and the same was true for Raspbian Jessie and earlier.

I had to include the vers=1.0 option because the default version in Stretch didn't work with my rather old GoFlex NAS, but I have no experience of WDMyCloud.

Maybe you could document the different mount commands you have tried, together with the reported errors? That might give a clue as to what's causing it.

Good luck! I hope you get it sorted.