Power Management - Sleep / Wake up Server when accessed

30,241

Solution 1

The best instruction I have found on the web was the XBMC wiki for WOL. In short (more info in the link):

  1. You need to enable WOL on your motherboard;
  2. Install ethtool: sudo apt-get install ethtool;
  3. Set Wake-on-LAN options: sudo ethtool -s eth0 wol g;
  4. Get it enabled at system start-up with an init script. There's an init script in the wiki link.

Untested; info from the wiki link

Solution 2

Further than sleep mode, what you're looking for is hibernate, as you want to save your state in your harddisk and shutdown completely the server.

So, as many have pointed, the answe is WOL (Wake On Lan). There are a lot of tutorials about it, but mainly you need to set up the following:

  • Your router has to bypass the magic packet (as the WOL packet is called) to your server, so you need to do the port forwarding. It's usually located in the LAN section. The default ports are 7 and 9.
  • Your motherboard needs to be listening on LAN port when is powered off. The most of modern MBs provide this feature, but is disabled by default. Check it! In my case, it is called "Power on by Ring on Lan".

Server doesn't need more setting than the suitable power management configuration to get the system down after an hour of inactivity (it could be done from System > Administration > Power management).

Obviously, you have to wait for a while after you sent the WOL packet, as your system needs to de-hibernate and it could take a few.

Good luck

Solution 3

I decided I wanted a solution to wake my media server automatically when accessed that wasn't dependent on dd-wrt.

I have a raspberry pi so I used it because it is low power and I don't mind keeping it on all the time, of course it could be run from any linux machine.

The final solution I found for myself was writing a little bash script. The raspberry-pi dependencies are etherwake and tcpdump. Both are not installed by default on rasbian. Also on the server Wake On Lan needs to be enabled as mentioned in the other posts.

sudo apt-get install etherwake
sudo apt-get install tcpdump

The wake script is as follows:

nano ~/wol.sh

Then:

#!/bin/bash

pingInterval=60 #time interval, in seconds, between checks that the server is still awake.
target=192.168.x.x  #WOL target ip address
targetMAC=00:11:22:33:44:55  #WOL target MAC

wake () {
    tcpdump -i eth0 -c 1 -p host $target
    etherwake $targetMAC
    #echo WOL sent to $target at $targetMAC
return
}

while sleep $pingInterval; do
varPing=`ping -s 1 -c 2 $target > /dev/null; echo $?`
    if [ $varPing -eq 0 ]; then
        #echo ping success
    else
        #echo ping fail
        wake
    fi
done

The primary idea is that it is run from my raspberry-pi which will wake the server if it notices a single arp request for the server. If the server is awake then it wont be listening for an arp request but send a few pings every now and then to make sure it is still awake.

I named the file wol.sh and made it executable. Then put it in the sudo crontab to launch @reboot as root. This is for tcpdump which needs elevated access to listen to eth0 and etherwake.

sudo chmod +x /home/pi/wol.sh
sudo crontab -e

add this to the bottom

@reboot sh /home/pi/wol.sh > /dev/null
Share:
30,241

Related videos on Youtube

KP65
Author by

KP65

Updated on September 18, 2022

Comments

  • KP65
    KP65 over 1 year

    I have a headless HP Proliant Microserver with ubuntu installed. This machine has samba shares on it serving media and I usually rdp or ssh into it. Now my issue is I want the machine to go into sleep mode(so the state is saved from ram to the harddrive) and it will seem like it is turned off after an hour of idling.

    If there is any attempt to access the samba share through LAN I would like it to wake up. Now my motherboard supports this function, can anyone point me in the right direction for achieving this easily?

    Thanks