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

Westie

  • Kitizen
  • ****
  • Posts: 1596
Restarting DSLstats after power cut
« 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.
Logged

Deathstar

  • Reg Member
  • ***
  • Posts: 138
Re: Restarting DSLstats after power cut
« Reply #1 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?
Logged
VMG1312-B10A Bridge Mode to ASUS DSLAC68U

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #2 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?
Logged

Weaver

  • Senior Kitizen
  • ******
  • Posts: 11459
  • Retd s/w dev; A&A; 4x7km ADSL2 lines; Firebrick
Re: Restarting DSLstats after power cut
« Reply #3 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.
Logged

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: Restarting DSLstats after power cut
« Reply #4 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.
« Last Edit: September 23, 2018, 07:57:33 AM by roseway »
Logged
  Eric

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #5 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.
« Last Edit: September 23, 2018, 04:09:35 PM by Westie »
Logged

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: Restarting DSLstats after power cut
« Reply #6 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
Logged
  Eric

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #7 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.
Logged

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: Restarting DSLstats after power cut
« Reply #8 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.
Logged
Broadband and Line rental: Zen Unlimited Fibre 2, Mobile: Vodaphone
Router: Fritz!Box 7530

jelv

  • Helpful
  • Kitizen
  • *
  • Posts: 2054
Re: Restarting DSLstats after power cut
« Reply #9 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.
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 #10 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... ;)
Logged

Weaver

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

Would sudo mount -a help? (Apol if I am missing the point here.)
Logged

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: Restarting DSLstats after power cut
« Reply #12 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.
Logged
  Eric

Westie

  • Kitizen
  • ****
  • Posts: 1596
Re: Restarting DSLstats after power cut
« Reply #13 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.
Logged

tiffy

  • Kitizen
  • ****
  • Posts: 1319
Re: Restarting DSLstats after power cut
« Reply #14 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 ?
Logged
BT FTTP 150/30, BT Smart Hub 2
Pages: [1] 2 3 4