Automatic WakeOnLan upon accessing MySql or FileShares

  Thread Rating:
  • 4 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
t4_ravenbird Offline
Senior Member
Posts: 184
Joined: Mar 2012
Reputation: 5
Post: #1
Hi all!

I have sent in a patch today (Ticket #12739) that adds a feature to XBMC :
XBMC will automatically issue a 'wake-on-lan' packet to MySql or FileShare Server right before it needs to contact them (if so configured).

There are different ways of doing this (plugins or os-specific scripts) but non of them have quite solved my needs, therefore this patch.
Hoping it will get accepted for a future build!
Edit : The patch has been merged and should become available from XBMC 13 (Gotham) Alpha 4 (May 2013)

**

Description (updated)

Feature is enabled under "system/settings/system/power saving/try to wake remote servers on access"

When feature gets enabled or shares gets added an autoscan will be done for any servers specified, either in shares or in MySQL settings.
The autoscan will if necessary create a file called 'wakeonlan.xml' and will add entries for these servers including macaddress which should be picked up in the scan.

Sample 'wakeonlan.xml'
Code:
<onaccesswakeup>
    <netinittimeout>60</netinittimeout>
    <netsettletime>500</netsettletime>
    <wakeup>
        <host>10.0.0.6</host>
        <mac>11:11:F2:11:DF:1E</mac>
        <pingport>3306</pingport>
        <pingmode>1</pingmode>
        <timeout>600</timeout>
        <waitonline>38</waitonline>
        <waitonline2>40</waitonline2>
        <waitservices>0</waitservices>
    </wakeup>
</onaccesswakeup>

netinittimeout [secs]
time xbmc will wait for network to (re)connect when booting or after resuming from suspend-mode
netsettletime [milli secs]
time to wait for network to be consistently connected before progressing
host
ipaddress (or network name) of machine you want to wake up
mac
macaddress
pingport
default 0 which will perform ordinary icmp ping. else a 'connect' attempt will be done to the specified port
pingmode
only applicable if pingport!=0, if 1 will not only connect to pingport but also wait until data is actually read back
timeout [secs]
specifies how long time (default 600) of inactivity must pass before a new 'wake-on-lan' check is performed. a good choice is to use same value as server's idle-timeout before entering sleep-mode
waitonline [secs]
time to wait for machine to wake up (advise is to set this to servers actual anticipated startup time)
waitonline2 [secs]
time to perform extended wait for machine to wake up
waitservices [secs]
additional time to wait after ping response, to allow server daemons to startup

useful pingport/pingmode combinations ;
pingport = 445 / pingmode = 0 - port 445 is used by samba (windows file sharing) and can be used for 'ping-probing' (but only pingmode = 0)
pingport = 3306 / pingmode = 1 - port 3306 is default MySQL port and useful if your server is the MySQL host
port 21 (ftp), 22 (ssl), 23 (telnet) are also likely to work OK if your server has that service installed

when using pingport = 0 (normal icmp ping) it is recommended to use waitservices = (ca) 5 to allow services on server to startup after server responds to ping. if using a different pingport it is normally not nessesary to add additional wait time
(This post was last modified: 2013-05-13 13:16 by t4_ravenbird.)
find quote
vexation Offline
Senior Member
Posts: 163
Joined: Jul 2009
Reputation: 1
Post: #2
I can't comment on the coding or whether it's suitable for inclusion but it's a nice idea anyway! I just wanted to make a suggestion (or see what other people think)..

Being able to wake the server is great but in my situation it can take 10-20 seconds for my makeshift server to properly resume from S3 after which XBMC has generally already timed out regardless. With that in mind I currently just have the hard-drives configured to go into power-saving mode instead. As they're all different sizes I haven't bothered with any RAID config so they need waking individually depending on the source accessed. These only take 5-10 seconds-ish to power up but it can still cause a delay and in some cases skipping for the first few seconds of a movie.

I'm just curious what you (and others) would think of including an option to also 'touch' or wake each of the media sources / drives in sources.xml so all the drives power up and are ready for access whenever XBMC is opened?
find quote
t4_ravenbird Offline
Senior Member
Posts: 184
Joined: Mar 2012
Reputation: 5
Post: #3
My server uses equally long time to start and XBMC would freeze ; that is no longer the case with the additions I made. It will stay black for those 10-20 seconds, but as soon as the server gets online XBMC continues and is good to go.
It would be even better if a message could be displayed while waiting, but that is probably not so easy because it is during skin-initialization that the MySql server is contacted..

To 'touch' your drives I would recommend an Addon- script. It should be relatively easy to put together. See http://wiki.xbmc.org/index.php?title=HOW...g_services
That way you can keep-alive the drives you like for as long as XBMC is running, not just on startup. And it should resume after a standby of your XBMC if that is how you run it.
find quote
Vascular Offline
Junior Member
Posts: 24
Joined: Aug 2009
Reputation: 0
Post: #4
This is great!! Would be perfect for my setup. Is there a way for me to add your code to my installation? What files do I need to change?
find quote
t4_ravenbird Offline
Senior Member
Posts: 184
Joined: Mar 2012
Reputation: 5
Post: #5
Thanks! To apply it yourself you would need to fetch the modifications from the ticket and then make a build by yourself (after also fetching the entire source for xbmc and merging my changes into it). It is quite a bit of work (I have only done it for the Windows-edition myself because I miss too much of the environments required for the other builds)

Best you can do is what you just did : state your interest for it ! That way we increase the chance that the team will accept the patch so we get official builds with the feature included.
find quote
regnets Offline
Senior Member
Posts: 197
Joined: Feb 2011
Reputation: 1
Location: Ratingen, Germany
Post: #6
This is insanely great!

It's a little odd that at first the sql server is queried and than the wakeonlan plugin is launching.

I hope anyone of the development team is reading this.

In my opinion it is a must have feature...

It is the only way to power down your sql server and let it restart from your xbmc clients!
find quote
Dam0 Offline
Fan
Posts: 443
Joined: Jun 2008
Reputation: 0
Post: #7
great concept

i look forward to using it in the future
find quote
zep123 Offline
Junior Member
Posts: 10
Joined: Jan 2011
Reputation: 0
Post: #8
Absolutely brilliant, I've been waiting for this feature for a long time!
find quote
DasMarx Offline
Junior Member
Posts: 28
Joined: May 2010
Reputation: 1
Post: #9
+1 on my side. you could easily make a workaround on windows pcs, but something like a raspberry pi or apple tv3 could be a problem without this patch.
find quote
matpol Offline
Member
Posts: 94
Joined: May 2008
Reputation: 0
Location: bournemouth, uk
Post: #10
has this been implemented?
find quote
Solo0815 Offline
Fan
Posts: 351
Joined: Sep 2004
Reputation: 0
Post: #11
We are after "Eden" -> implement it!

there are only 10 sorts of people: those who understand binary and those who don't

PC: Kubuntu 14.04 and Win7 --- Raspberry Pi: OpenELEC --- VU+ Duo: VTi 7.0.x --- NAS: OMV 1.0.x with XBMC-Server
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #12
I find this patch very intriguing. This si something I have been wanting for a very long time. I plan make a build with this patch today and see how it performs.

Can you explain the <tmout>700</tmout> option a bit more? Why would we need to constantly send wake-up packets to the server?

Read this before using these builds.
XBMC win32 SVN builds
Changelog
(This post was last modified: 2012-04-12 19:36 by kricker.)
find quote
t4_ravenbird Offline
Senior Member
Posts: 184
Joined: Mar 2012
Reputation: 5
Post: #13
(2012-04-12 19:33)kricker Wrote:  I find this patch very intriguing. This si something I have been wanting for a very long time. I plan make a build with this patch today and see how it performs.

Can you explain the <tmout>700</tmout> option a bit more? Why would we need to constantly send wake-up packets to the server?

Thanks!
The 'timeout' specified does not mean that a new wake-up is done at this interval.
Instead is defines the time (in seconds) of inactivity that should pass before a new wake-up is sent.
So, for as long as files are beeing accessed on the server there will not (ever) be re-sent a wake-up, the wake-up will be done after activity stops and has been idle for the time set in 'tmout'

The idea is that if you have a server that is set to go into suspend-mode after e.g 30 minutes of inactivity then you can setup XBMC to send a new wake-up if XBMC detects that no access has been done towards that server for more than e.g 25 minutes (to make sure we wake it up again)
This new wake-up will not be done just because the timer expires, instead it will be done 'just-in-time' when a file-access is done after the timer has expired.


Hope that makes it clearer?
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #14
I think so.

I have such a server. After 20 minutes of the all disks being idle, the server goes to sleep.

With this setting then, if the timer expires, the new wake event will be sent when I try to access files from the server again. If I don't access that server again the packet will not be sent.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #15
So with t4_ravenbird's modified files I created a patch for the current master branch. With my preliminary testing things are looking good. I am not using mySQL, just the default XBMC databases. I let my server fall asleep, then tried to play a file from it. The server woke up and then played back perfectly fine.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
Post Reply