Kodi Community Forum
starting NAS server at boot - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Linux (https://forum.kodi.tv/forumdisplay.php?fid=52)
+---- Thread: starting NAS server at boot (/showthread.php?tid=123624)

Pages: 1 2


starting NAS server at boot - MacUsers - 2012-02-22

Hi there,

(I know it's not really "XBMC" issue but I thought I just try my luck within the experts here)

I have a NAS (Ubuntu 11.10/NFS4) which goes to sleep when not in use and I tend to send an WOL magic-packet to wak up te server as soon as the XBMC box starts. So I wrote this little init.d script (on the XBMC box), namely: sendwol, to send the WOL signal during the boot:

Code:
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:       sendwol
# Required-Start: $remote_fs $local_fs
# Required-Stop:  $remote_fs $local_fs
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: Send WOL to mserv
### END INIT INFO
#
. /lib/lsb/init-functions

do_start() {
    wol=`which wake-on-lan`
    if [ "$?" -eq 0 ]; then
        $wol mserv
    else
        echo "wake-on-lan not installed"
    fi
    exit
}

do_stop() {
    echo "Action not supported"
    exit
}

case "$1" in
  start )
        do_start
        ;;
  restart|reload|force-reload )
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop )
        do_stop
        ;;
  * )
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

exit 0

and then created all the necessary Sys-V rc?.d links:
Code:
# ls -l /etc/rc?.d/* | grep sendwol | awk '{OFS=" "; print $8,$9,$10}'
/etc/rc0.d/K20sendwol -> ../init.d/sendwol
/etc/rc1.d/K20sendwol -> ../init.d/sendwol
/etc/rc2.d/S20sendwol -> ../init.d/sendwol
/etc/rc3.d/S20sendwol -> ../init.d/sendwol
/etc/rc4.d/S20sendwol -> ../init.d/sendwol
/etc/rc5.d/S20sendwol -> ../init.d/sendwol
/etc/rc6.d/K20sendwol -> ../init.d/sendwol

But it's not working. The script: wake-on-lan, which is actually in: /usr/local/bin, works just fine by its own and if the ran this init script manually (e.g. /etc/init.d/sendwol start) it's works just fine as well but not during the system boot time. Does anyone know what am I missing? The WOL is one of the important parts in my setup, so any help to solve/debug this issue would be very much appreciated. Cheers!!


- MacUsers - 2012-02-23

Sad I still can't make it work, even though my other init-scripts are working fine. Any one, with any suggestion? Cheers!!


- teeedubb - 2012-02-23

Woah... that's all of work to run a command on boot. Have u tried executing the wol command from /etc/rc.local?


- teeedubb - 2012-02-23

Also xbmc has an wol addon that can be executed at different times/events.


- MacUsers - 2012-02-23

Sending WOL itself is not a problem; my goal is to send the WOL signal as soon as [possible] the htpc starts, so that XBMC doesn't need wait long to get all the necessary mount points, hence running from init.d directory. Cheers!!


- vikjon0 - 2012-02-23

I have no knowledge in this area, but should probably not send it before you have network on the htpc...


- Mus_ - 2012-02-23

I'm guessing this doesn't work because the network is not up when you start the init.d script.
It would make more sense to start the script as soon as the network is up, have a look at the post-up command in /etc/network/interfaces:
http://manpages.ubuntu.com/manpages/oneiric/man5/interfaces.5.html

I'm actually doing the same thing on my Arch Linux machine. Arch Linux has it's own network configuration, but here is my "post-up script" if it helps:

Code:
#!/bin/sh
wol <MAC>
echo "waiting for server..."
until ping -c 1 <IP>; do true; done &> /dev/null
for i in /media/Daten/ /home/xbmc/.xbmc/userdata/Thumbnails/; do
    echo "mount $i"
    mount $i
done
This is imho much "cleaner" than an init.d script and has the advantage that it works after suspend/resume as well.


- MacUsers - 2012-02-23

@vikjon0, @Mus,
most probably "network" is the problem; I'll retry with "Required-Start: $networking" and see if it works.
I used to do that with automount script - every time XBMC tries to [auto]mount a directory, check and sends an WOL but this time I gave inint.d a go. I think, post-up script is a better option. Thanks!


- MacUsers - 2012-02-23

Mus_ Wrote:This is imho much "cleaner" than an init.d script and has the advantage that it works after suspend/resume as well.
Thanks! it worked.
As opposed to post-up, I simply put my script in the /etc/network/if-up.d/ and it worked straight away.

On a separate note: If I put the server (Ubuntu v11.10) in sleep/hibernate, WOL works just fine but if do soft-off (e.g. shutdown -h now) it doesn't. Do you see the same thing? This behavior is not observed on 10.04 (although I can't remember if I did anything extra to achieve this). any idea? Cheers!!


- Mus_ - 2012-02-23

MacUsers Wrote:On a separate note: If I put the server (Ubuntu v11.10) in sleep/hibernate, WOL works just fine but if do soft-off (e.g. shutdown -h now) it doesn't. Do you see the same thing? This behavior is not observed on 10.04 (although I can't remember if I did anything extra to achieve this). any idea? Cheers!!
I think this is something you have to configure in your BIOS settings.
I haven't tested this on my machine because my system is completely encrypted, so waking it up from soft-off doesn't make sense because I have to enter the password to boot it up anyway.


- MacUsers - 2012-02-23

Mus_ Wrote:I think this is something you have to configure in your BIOS settings.
Yes, but not this time, I guess. If I use the same machine (using different hard-drive) for Ubuntu 10.10, it works. Cheers!!


- Mus_ - 2012-02-23

MacUsers Wrote:Yes, but not this time, I guess. If I use the same machine (using different hard-drive) for Ubuntu 10.10, it works. Cheers!!
Post from both ubuntu installations:

cat /proc/acpi/wakeup

and

sudo ethtool eth0 | grep Wake-on


- MacUsers - 2012-02-23

From v11.10
Code:
root@htpc:~# cat /proc/acpi/wakeup
Device    S-state      Status   Sysfs node
P0P1      S4    *disabled  pci:0000:00:1e.0
EUSB      S4    *disabled  pci:0000:00:1d.7
USBE      S4    *disabled  pci:0000:00:1a.7
P0P4      S4    *disabled  pci:0000:00:1c.0
P0P5      S4    *disabled  
P0P6      S4    *disabled  
P0P7      S4    *disabled  
P0P8      S4    *disabled  
P0P9      S4    *disabled  pci:0000:00:1c.5
GBEC      S4    *disabled  
USB0      S4    *disabled  pci:0000:00:1d.0
USB1      S4    *disabled  pci:0000:00:1d.1
USB2      S4    *disabled  pci:0000:00:1d.2
USB3      S4    *disabled  
USB4      S4    *disabled  pci:0000:00:1a.0
USB5      S4    *disabled  pci:0000:00:1a.1
USB6      S4    *disabled  pci:0000:00:1a.2
P0P2      S4    *disabled  pci:0000:00:01.0
P0P3      S4    *disabled
ethtool looks fine:
Code:
root@htpc:~# ethtool eth0 | grep -i wake-on
    Supports Wake-on: pumbg
    Wake-on: g

Result from v10.10 in a min.......


- MacUsers - 2012-02-23

This is from v10.04

Code:
root@htpc:~# cat /proc/acpi/wakeup
Device    S-state      Status   Sysfs node
P0P1      S4     disabled  pci:0000:00:1e.0
EUSB      S4     disabled  pci:0000:00:1d.7
USBE      S4     disabled  pci:0000:00:1a.7
P0P4      S4     disabled  pci:0000:00:1c.0
P0P5      S4     disabled  
P0P6      S4     disabled  
P0P7      S4     disabled  
P0P8      S4     disabled  
P0P9      S4     disabled  pci:0000:00:1c.5
GBEC      S4     disabled  
USB0      S4     disabled  pci:0000:00:1d.0
USB1      S4     disabled  pci:0000:00:1d.1
USB2      S4     disabled  pci:0000:00:1d.2
USB3      S4     disabled  
USB4      S4     disabled  pci:0000:00:1a.0
USB5      S4     disabled  pci:0000:00:1a.1
USB6      S4     disabled  pci:0000:00:1a.2
P0P2      S4     disabled  pci:0000:00:01.0
P0P3      S4     disabled
The * are missing here...

and ethtool:
Code:
root@htpc:~# ethtool eth0 | grep -i wake-on
    Supports Wake-on: pumbg
    Wake-on: g



- Mus_ - 2012-02-24

hm, not sure what's going on there, I would have expected some kind of difference here (obviously Wink ).
No idea what the * mean...
I guess GBEC is the network adapter (Gigabit Ethernet Controller). You could enable it, but this is probably not going to make a difference since it is disabled on the system it works on as well, but it's worth a try.

as root:
echo GBEC > /proc/acpi/wakeup

You could also check
/sys/class/net/eth0/device/power/wakeup
for a difference, but this may just show the same state as /proc/acpi/wakeup.