WOL NAS on RPI startup

Raspberry Pi related support

WOL NAS on RPI startup

Postby chrichri » 12 Mar 2019, 10:22

Hi there,

I would like to wake up my NAS when my RuneAudio Raspberry boots.

What I did so far:

- installed wol on RPI
- wake up NAS from commanline works:

Code: Select all
===============  RuneOS distribution  ===============
  ____                      _             _ _       
 |  _ \ _   _ _ __   ___   / \  _   _  __| (_) ___ 
 | |_) | | | | '_ \ / _ \ / _ \| | | |/ _` | |/ _ \
 |  _ <| |_| | | | |  __// ___ \ |_| | (_| | | (_) |
 |_| \_\\__,_|_| |_|\___/_/   \_\__,_|\__,_|_|\___/
                                                   
================  www.runeaudio.com  ================
RuneOs: Experimental Beta 0.5 20180903
RuneUI: 0.5b (gearhead)
Hw-env: RaspberryPi 2 / 3


root@runeaudio(rw):~# wol 00:11:32:3B:2C:D0
Waking up 00:11:32:3B:2C:D0...
root@runeaudio(rw):~# ping 192.168.1.101
PING 192.168.1.101 (192.168.1.101) 56(84) bytes of data.
64 bytes from 192.168.1.101: icmp_seq=1 ttl=64 time=0.829 ms
64 bytes from 192.168.1.101: icmp_seq=2 ttl=64 time=0.387 ms
^C
--- 192.168.1.101 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1068ms
rtt min/avg/max/mdev = 0.387/0.608/0.829/0.221 ms
root@runeaudio(rw):~#


- added command to /var/www/command/rune_SY_wkr as follows (see line 58):
Code: Select all
...
  53 // Connect to Redis backend
  54 $redis = new Redis();
  55 $redis->connect('/run/redis.sock');
  56
  57 // wake on lan NAS
  58 sysCmd('wol 00:11:32:3B:2C:D0');
  59
  60 // if os updates are needed
  61 if (file_exists('/srv/http/command/update_os.php')) {
  62     include '/srv/http/command/update_os.php';
  63     updateOS($redis);
  64 }
...


Unfortunately the NAS does not boot when booting the RPI....any hints what I might do wrong?

Thank you in advance. Here is my complete debug info: https://pastebin.com/85RC0Wqw

Best
Chris
chrichri
 
Posts: 11
Joined: 16 Jan 2019, 07:10

Re: WOL NAS on RPI startup

Postby janui » 12 Mar 2019, 13:25

Hi chrichri,
chrichri wrote:…I would like to wake up my NAS when my RuneAudio Raspberry boots...
Your changes look fine. How long does it take for the NAS to become available after the wol? Is it possible that the NAS has not yet fully started when Rune attempts to mount it?
If it fails on the first attempt Rune will attempt to mount the NAS again after about 15 minutes. Could you check if it is mounted after waiting for 15 mins or so?
If it mounts after waiting 15 mins you can change this line in /var/www/command/rune_SY_wkr to a value in half seconds which your NAS needs to become available:
Code: Select all
$savecpu_mnt = 1;
So say it takes 60 seconds for the NAS to start, use a value of 70 or so for a bit of leeway, double it giving 140 half seconds. It should look like this:
Code: Select all
$savecpu_mnt = 140;
It will then wake up and mount the NAS in the shortest possible time. If the NAS is already up it will mount immediately without waiting.
janui
User avatar
janui
 
Posts: 540
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: WOL NAS on RPI startup

Postby chrichri » 13 Mar 2019, 10:35

Hello janui,

thanks for the reply. Unfortunately this is not a mounting issue. The NAS does not boot when launching the RPI, however it boots when manually sending the wol request in the ssh console.

The problem seems to be the following: My router which is running the DHCP server is not the fastest one. It takes a few seconds until IP adresses are assigned to the clients (even though the IP is always the same, static IPs are defined for NAS and RPI in the router's DHCP configuration).

When I add a sleep command before the wol request

Code: Select all
 
  57 // wake on lan NAS
  58 sleep(60);
  59 sysCmd('wol 00:11:32:3B:2C:D0');


the WOL request works. But of course boot time is delayed. I will try to find the minimum possible sleep time...

A more elegant way would be to check if an IP adress is assigned before the WOL request. Something like this:

Code: Select all
continue = false
do {
    sleep(1)
    if (IP assigned) {
        sysCmd('wol 00:11:32:3B:2C:D0');
        continue = true;
    }
} while (continue==false);


I have little php experience though...what would be the best way to check the IP assignment?

Best regards
Chris
chrichri
 
Posts: 11
Joined: 16 Jan 2019, 07:10

Re: WOL NAS on RPI startup

Postby janui » 13 Mar 2019, 23:24

Edit: post deleted 15-03-2019
Last edited by janui on 15 Mar 2019, 14:50, edited 1 time in total.
User avatar
janui
 
Posts: 540
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: WOL NAS on RPI startup

Postby janui » 15 Mar 2019, 14:40

Hi chrichri,
I have deleted my previous post as it is not really a good way to integrate a call to wol. I also have suspicions that it would not work correctly.
As a better solution I suggest you create a file called /usr/lib/systemd/system/wol.service, with this content:
Code: Select all
# This file name: /usr/lib/systemd/system/wol.service (-rw-r--r-- 1 root root)
# Wake on lan request for NAS after routable network connection established
# In order for network-online.target to work it needs systemd-networkd.service to be active
# File permissions set with: chown root.root /usr/lib/systemd/system/wol.service ; chmod 644 /usr/lib/systemd/system/wol.service
# Enable with: systemclt enable systemd-networkd wol
# Disable with: systemclt disable systemd-networkd wol
[Unit]
Description = (WOL) Wake on Lan request for NAS
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wol 00:11:32:3B:2C:D0
[Install]
WantedBy= multi-user.target
After creating it run these commands:
Code: Select all
chown root.root /usr/lib/systemd/system/wol.service
chmod 644 /usr/lib/systemd/system/wol.service
systemctl daemon-reload
systemctl enable systemd-networkd wol
Then reboot.
You can check that it has worked by running this command:
Code: Select all
journalctl | grep -i -E 'reached|wol'
janui
User avatar
janui
 
Posts: 540
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: WOL NAS on RPI startup

Postby chrichri » 16 Mar 2019, 11:21

Hello janui,

works like a charm! And this definitely a more elegant and reliable way!

There is one little disadvantage: It takes ~30s longer to wake up the NAS after RPI boot compared to the entry in rune_SY_wrk combined with a sleep(15) command. Seems like the network is up before the target "network is online" is reached...

Anyway, I will stick with this solution as this is the more reliable way. Thanks again janui for your support and have a nice weekend!

Best regards
Chris
chrichri
 
Posts: 11
Joined: 16 Jan 2019, 07:10

support RuneAudio Donate with PayPal


Return to Raspberry Pi

Who is online

Users browsing this forum: cmh714, hondagx35 and 2 guests