Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was wondering if it were posible to make my server go to sleep after a set period of time, but still be listening for lan requests. I use my server as a media server that might get used 3 or 4 hours a day and it is really a waste of power to have it running all the time. However I don't want to run up to the second floor to switch it on when we want to watch a movie. I saw a few posts about stopping this from happening but how do you enable it?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Wake on LAN is a BIOS and NIC feature, not an OS feature, that is, you need a supporting BIOS and NIC to do it.

Once you've enabled it in your BIOS (if you can), you can check if your NIC has WOL support enabled by checking the output of ethtool [interface].

If the value of Supports Wake-on contains g, your NIC supports WOL magic packets.

To check if it is actually enabled, take a look at the value of Wake-on. If it contains g, your NIC has magic packet support enabled.

If it isn't enabled, run the following:

ethtool -s [interface] wol g

You'll have to issue this command every time your system starts, so add it to the appropriate place. In Ubuntu, perhaps the best place would be as an up rule in /etc/network/interfaces, or the equivalent for your network manager.

share|improve this answer
    
thanks for the answer! but by "every time your system starts" do you mean wake, reboot, or both? –  Craig Smith Nov 19 '12 at 20:10
    
@CraigSmith That would depend on your NIC, but likely only on boot. –  Chris Down Nov 19 '12 at 20:17
    
thanks for the info, lots of help~! –  Craig Smith Nov 19 '12 at 20:34

I know this was asked a year ago, but I've found a few solutions. The first one uses powernap and a script to check for specific running processes, and can be found here.

Second I saw online was linux questions. This uses pings to another machine.

I also flashed a router with DD-WRT to try out- at the dd-wrt wiki. These are very nice elegant solutions but the issue I had with them is they are not suited for an internal media server, because the log only catches accepted packets from outside of the network. If you want an internal only media server this just doesn't work.

For dd-wrt this offers a really nice solution to this using VLAN's. Basically put the server on it's own internal subnet and monitor traffic to that VLAN, then the previous script works. This works well, but in my experience the router and build of dd-wrt whenever I used the vlan feature DHCP crashed.

I decided I wanted a solution to wake and suspend my media server automatically when accessed that wasn't dependent on dd-wrt. I have a raspberry pi so I used that. 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.

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

The wake script is as follows:

#!/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

The sleep script is run from the media server using the same principle. If there is no traffic to the server(excluding icmp or arp) during the interval of scanning I chose 1 minute. Then it adds to a counter which I named sleepiness. After the sleepiness reaches 10 or 20 meaning its had no traffic in and out for twenty minutes then it sets the sleepiness to zero then it issues the command pm-suspend to fall asleep. It packets are received and sleepiness!=0 then it does a sleepiness -1. So if it captures a stray packet or some how do you do's from the router it won't reset the count back to zero, but rather just do a -1 from the counter. I put this in there because it allows a grace period of gently falling to sleep as the packets decrease over a period of time rather than having absolutely zero packets for 20 consecutive minutes.

This is maybe not the best because it has to call tcpdump on both machines, Involves constant writes to disk (server side). For the writes to disk I mounted a sacrificial usb and that's where my capture file is saved to prevent wear to my actual HDD. I am a beginner, but I was proud of my little solution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.