Overview
I have a client computer running Kodi on Ubuntu. I also have a separate computer acting as a server. When i switch on the client computer, i want the server to switch on too.
This method can be used for any linux client to switch on any server. Kodi have a setting to wake a server, but it doesn't always seem to work properly. This method always does the job.
Enable Wake on Lan (WoL) on server
Our How to enable Wake on Lan article has full instructions on how to make sure your server is set-up to be woken up by a Wake-on-Lan packet.
Find out the server MAC address
Access the server via ssh or open a terminal.
ifconfig | grep HWaddr
Make a note of the MAC address which appears on the same line as eth0
, as you will need it next.
Create Wake on Lan (WoL) script
Access the client machine via ssh or open a terminal.
cd /etc/init.d
sudo nano mywol
Copy the following script content:-
#! /bin/sh
#
# location /etc/init.d
#
# MAC address of backend
SERVER_MAC=90:9Z:34:TR:Z9:A7
# Issue wakeonlan at intervals until our own network interface
# is active and the magic packet is successfully sent.
#
until /usr/bin/wakeonlan $SERVER_MAC > /dev/null 2>&1 ; do
sleep 1
done
exit 0
Paste clipboard contents into nano using:- shift + insert
Replace the value of SERVER_MAC
with the MAC address of the server you want to wake-up.
Save file using ctrl + o
Exit nano using ctrl + x
Make sure the scipt is excecutable.
sudo chmod 755 mywol
The above could have been done using an upstart job, but i have never found this to work properly.
Running the script on system boot
A program called wakeonlan is required on your client computer to issue wake-up messages.
Install wakeonlan using the following commands:-
sudo apt-get update
sudo apt-get install wakeonlan
Now we can test our script
Switch off your server then on the client, do the following:-
sudo /etc/init.d/mywol
After a few moments the server will switch on.
If nothing happens, make sure you have:
- Used the correct MAC address in the script
- Have applied this article to your server
Once we are happy the script works we need to make it run on boot.
sudo update-rc.d mywol defaults
To test this, switch off your server, then reboot your client. The server should start-up a few moments after the client.