4

I am looking for a way to put my Linux home server in standby after a period without any "heart beat" network activity. I would like to use WOL packets as a heart beat signal. These packages will be send by several clients each with an interval of, lets say, every 15 minutes.

An actual example is therefore more than welcome.

migrated from serverfault.com Oct 26 '12 at 12:59

This question came from our site for system and network administrators.

  • 1
    Why not just disable standby on the server? In my world, servers and standby should never be in the same sentence, unless people tells you not to do it ;) – Frederik Nielsen Oct 26 '12 at 10:41
  • 3
    Because I do not want my home server to be powered on the whole day. But only when PC's are powered on, or smartphones te be in WiFi range. – Alain Oct 26 '12 at 11:23
  • Have you tried just pinging the server? I don't know if that is enough to make it not go to sleep. – Frederik Nielsen Oct 26 '12 at 12:37
  • Thanks for you suggestion. Currently the server does not go into standby by itself. The solution that I am looking for should take care of this as well. I am planning to add service monitoring, to prevent the server going to sleep while, for example, a backup process is running. But first things first. ;-) – Alain Oct 26 '12 at 12:49
  • 1
    @ChrisS "Modern hardware 'wears' the…" Well, sort of. A power/heat cycle does induce a certain amount of wear. But so does running it. That power cycle is the same as running it for X time. So, if X is less than the amount of time you had it not running, you're prolonging life. If X is greater, you're shortening life. I doubt X is more than a few hours, even for the worst-case component. (A lot of components are expected to have rapid heat cycling, e.g, the CPU) – derobert Oct 26 '12 at 15:48
1

Here are a couple of easy ways for your server to check if other devices are using it:

  • Check the arp cache using /usr/sbin/arp or by reading /proc/net/arp. You'll see in there all the devices which the server has communicated with fairly recently. This includes the MAC address, so you can find your phone, etc. even in the face of DHCP.
  • Use ping (or arping, which won't be blocked by host-based firewalls) to actively poll your hosts.
  • Set up iptables rules to match the hosts you're interested in, then check their packet counters. If the counters are increasing, those hosts are active.

All of those are doable with fairly simple scripting. You can then have the script put your server in S3, S4, or even G2/S5 and let Wake-on-LAN wake the server back up.

NOTE: On a lot of desktop boards, S3 doesn't actually save that much power. Meter it before you bother. Or make sure to use at least S4.

1
#!/bin/bash
while
  true
do
  shutdown -c
  shutdown -h +15 &
  echo "Waiting for magic packet to continue ..."
  nc -l 9
done

As requested, here's the missing documentaion. Late, but maybe still helpful:

The loop cancels the previous shutdown command and sets a new one to 15 minutes. Then it opens port 9 with NetCat utility. If a packet on this port is received, the loop will start over, otherwise the computer will shut down.

  • Can you add some detail to this script? – slm Jan 22 '14 at 17:39
  • 1
    This script should work, but I concur with @slm -- the purpose of this site is to educate as much as it is to answer; explaining how this script works and why it solves the stated problem would improve this answer. – Shadur Jan 22 '14 at 18:00
0

You can put your server into sleep with s2disk and s2ram. The question when? is up to you. You may run some cron jobs and ping some IP's when they do not answer, then go to sleep. Or what ever.

With tools like etherwake or wakeonlan you are able to wake a machine from sleep by sending a magic packet to network.

Good reads Wake-on-LAN

0

You can try sspender https://github.com/mountassir/sspender

It allows you to suspend your machine based on pre-defined CPU/Disk usage, and makes sure the machine wakes up at certain times when you need it to be ON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy