Linux Server, Wakey, Wakey

We all know we should save energy and not leave computers on all the time. It is probably better for the computer, too. But when you operate a home server, it isn’t feasible to just turn it on when you want to use it and then turn it off again. Or is it? [Daniel] decided that was exactly what he wanted to do, and it was quite an adventure to get there.

The trick is to use a Raspberry Pi — they don’t draw nearly the power a big computer does — to stay awake to facilitate the process. The Pi watches for ARP requests for the sleeping machine and replies on its behalf so that other network nodes can find the machine even when it isn’t on.

The server itself detects if it is idle in a cron job. When it finds that there are no SSH or other service connections for a set period of time, it suspends the machine to RAM, putting it in a low-power mode. Waking a sleeping computer up over the network is a solved problem, and [Daniel] investigated several wake-on-lan solutions.

There were several oddities to work out, including a Mac pinging an unused network share, and a router that was making NetBIOS queries. However, [Daniel] found a $30 router that could do port mirroring and that helped a lot with troubleshooting.

This is one of those things where his recipe won’t exactly fit your situation. But the post has a lot of good information and some nice tricks for troubleshooting any kind of network bizarreness.

Wireshark is a great tool for this kind of work, too. Another useful technique is recording network traffic and playing it back.

39 thoughts on “Linux Server, Wakey, Wakey

  1. In theory, Wake on LAN is a solved problem. However, many years ago I tried something similar to this, and had issues with waking up a suspended computer. I don’t remember details, it was too long ago, and I eventually gave up on this idea, but in general, issue was that computer didn’t want to wake up from suspended state. When computer was powered off, Wake on LAN worked fine, but when it was suspended, it didn’t work.

    1. The last time I measured a desktop in suspend to ram, it only reduced the power usage from idling at 100 down to 50W, but as always YMMV. For that use case, I turned it off despite the 10 minute boot time to save power (and thus money) instead of time.

      1. I have a Ryzen 5800X system with a “Modern Standby” capable power supply, and I’ve turned all the power saving features on in the UEFI. This removes S1/S2/S3 sleep and makes the system toggle between “S0 working” and “S0 low-power idle” when it’s put to sleep.

        The system idles at about 80 watts according to my UPS, and when I put it to sleep it uses 1 watt. As a bonus, it takes about two seconds to wake from sleep if you press a key or whatever. It’s a really good user experience.

    1. Port mirroring is like “copy all (TCP,UDP,ICMP…) packets coming and/or leaving” the monitored interface to another port.
      Simple … but one should not abuse this feature: it takes a toll on the CPU load of the router. At least on most cheap hardware.

      1. Yup. If folks need a low budget example: TP-Link TLSG108E

        If you want fullest captures of a wireless device, and your router doesn’t provide tcpdump, then use one of these switches with a cheap OpenWRT access point (like a gl-ar750s). Then you will only capture what’s passing through the AP. No filtering to mess with.

  2. My solution was to run on the RPi a telegram bot that only allowed me to chat with, and that responded to two commands: one to turn on the computer, and another to use uPnP to tell me the current external IP (I have dynamic IP).

  3. Well, I tried this, but I realized that my networking equipment would send unicast and broadcast packets to the server in order to update ARP tables, every 2 minutes. Basically a way of saying “are you theeeereeee??”. My sleeping server has no way of telling if that packet is an ARP request that can be brushed off, or a legitimate network access request, so that whole idea was trashed by some unwanted behavior… If only ARP offloading was available on linux…

    I eventually solved that problem going up in the OSI layer: I put my server on a different subnet, behind a configurable router-firewall. Each time the firewall sees a new connection request to specific ports (samba or HTTPS), I tell iptables to log that.

    A separate process then monitors the logs for such entries, and triggers a WOL packet upon finding a matching entry.

    It does indeed introduce some delay between request and wakeups, but for samba shares, backups and nextcloud it works beautifully and saves me 5€ a month on my power bill!

  4. Not sure why you would need to add another computer (raspberry pi) to the system. As others have mentioned, wake on lan is a solved problem. Many cheap residential-use routers support sending the “magic packet” out of the box, and if not, various opensource firmwares for these routers have supported the feature for about 20 years.

    1. For me keeping a Raspberry Pi running is already a waste of energy. It adds up quickly in 365 Days. If you are going down the have a running computer to wake a computer at least be decent enough to scale down the always on running computer to something below 1 Watt.

      I get that there is some automation going on here with the arp packet watching, but I don’t quite get why. If your server needs more than 30 seconds to wake up, then the connection will have timed out already. The you can go the Wake on Lan route for manual wakeup again, or some other wake up system. Still no need for a RasPi.

      1. ARP and mDNS packets are Broadcast and Multicast respectively so will not wake the server because it can only respond to WoL magic packets and unicast packets. Hence the R-Pi answering on behalf of the server.

        Applications on Client Devices use IP addresses that must be resolved to unicast MAC addresses on the LAN. Applications cannot be expected to send Magic Packets for standard WoL situations (how would you configure your TV to do this, for example?). Similarly neither can a router if the two communicating device are on the same LAN because packets do not traverse the router.

        So the R-Pi acting on behalf of the server for the ARP and mDNS queries allows the client application to obtain the unicast MAC of the server during MAC address discovery and then to open a standard IP connection directly to the server MAC address just as it would in any normal situation. There will be a small delay in opening the IP connection but this is well within standard delay timeouts and will not upset most applications.

        This is transparent WoL for any situation without any configuration required on any client. Very clever.

  5. “We all know we should save energy and not leave computers on all the time. It is probably better for the computer, too.”

    Maybe, maybe not. I got longevity out of mostly-on with clean power during it’s lifespan.

    1. I think that the endless heating and cooling associated with switching things on and off ends up reducing the lifespan. My PC has been on 24/7/365 for like 7 years, and still going strong.

  6. My at home solution was to move things that ran on big hardware to little hardware. I replaced on file server with a thin term and a big external disk. Went from near 200W and a lot of noise from all the fans to under 20W and zero noise. Webserver moves likewise, though V1 of it used a usb stick to hold the web stuff, and even though it was mounted RO, it only lasted a couple of years, so the V2 solution was a ramdisk that when you start copies the USB stick to that. Both use tinycore and the bare minimum software to do the job. I was amazed with the web server. Going from magnetic disks and the old redhat server with the default apache to the ramdisk, tinycore and lighttpd, the difference was shocking. I was surprised as I was hoping for about the same performance and it was much faster. I mean why run a pi to turn a server on if the pi can do all the lifting? This will not work for big things that get hit hard, but for around the house…

    1. 20W is great, although it can be reduced. With an average power price of 0.20 $/kWh, running that 24/7 would cost you 35$+taxes annually. With a custom wake system you could reduce that to pennies.

  7. Meanwhile I’m powering down raspberry pis using smart plugs and am even buying very specific smart plugs so those don’t draw too much power either.

    I guess my apartments power consumption is orders of magnitudes lower than that of the projects author 😅

  8. Well, powering down my Dell poweredge would defeat the real pupose of the server: besides keeping all my multimedia at the ready, it keeps my wife’s plant room warm and cozy all year long here in the snowbelt. . .

  9. i think generally the better solution is to use intermediate power save modes within the computer. like, if your disks still spin, then they can spin down. a ton of things like SSD and GPU only consume meaningful current when you’re using them. a lot of even desktop-class CPUs these days consume almost nothing when they’re idle (HALT / WFI sort of instruction). and of course it helps to have things like a CPU fan that can turn off or slow down.

    the neat thing is, i don’t think you really have to give anything up. a modern cellphone is simply always on. if you look at the logcat on an android phone, you can see that even when it was inert, it was still talking to itself every couple seconds doing routine housekeeping. and yet when it isn’t “doing anything”, it doesn’t get hot.

    it’s just amazing to me that since i don’t run a browser on my laptop, its cpu is 99% idle even when i’m using it, and i get about half again more battery life than advertised. and my basement ‘server’ uses a ton less power when i’m running just screen and nvi than when i’m running make -j. now i wish i had a kill-a-watt sort of meter so i could quantify that…it must be low because the PSU fan died years ago and it hasn’t burned out yet. :)

    i just bring this up because the irony is that, while raspberry pi is relatively low draw for such a powerful computer…it is just about worst-in-class for power save modes, and there’s jack-all you can do about it because those decisions are all made behind a closed source wall in the ‘videocore’ coprocessor.

    but if your home PC is drawing more than 100W idle, i think you have way lower-hanging fruit than wake-on-lan.

    1. Actually getting a desktop/server to go under 100w isn’t trivial – the hardware drivers/firmware, BIOS and configuration tend to prevent it actually getting to the lowest power states properly. Laptops are generally a bit of a different story – battery life is a big selling point and the hardware is all identical (if you don’t have anything external connected, which again can prevent it) so they tend to ship out of the box able to idle better as it was a major design goal, so all the firmware is actually capable of it. Plus they generally have a rather puny max power draw anyway, so being under 100w is probably true will at 100% load… Unfortunately laptops generally suck for being what you would actually want in an always on computer, as they tend to have bugger all IO expansion potential, slower network, low disk space, lack RAM, have cooling solutions that don’t work well when tossed in the rats nest behind your rack/desk etc.

      There is just too much stuff on most desktops that need power and not all motherboards even support turning off that bit while its not in use at all, and because they are always connected to the wall alot of the devices you might put in are very much optimised at max performance not idle…

      1. My proxmox server run at 35w or less. It’s an HP ProDesk. My Truenas server has 6 spinning hard drives, 4 port nic and 2 port SFP+ nic and only pulls about 65w under full load, about 35 at idle. Desktop 5600x and 3070 is well under 100w at idle, around 60w if I recall. So that’s 2 servers and a desktop, not much over 100w when all idle.

        1. Didn’t say it couldn’t be done, there are ‘desktop’ cpu that are low wattage enough to stay under 100w, heck under 30w at full load anyway. But there are more than enough mobo’s and PCIe devices that won’t let you get even close to those low powerstates that lets the common CPU really get good idle power draw.

          With the right setup you can have a very very modern and performant server/desktop that spikes up to 1Kw+ idling down at something in the low 5-15w range, but it really isn’t trivial to do so as desktop parts don’t tend to just play nice with the lowest powerstates!

          Plus to get that low you really need SSD, as HDD are such high draw if they are spinning and generally still higher draw when spun down ‘on’ than the inactive SSD. Also probably can’t have high speed networking as those are more energy intensive in general and ‘idle’ does not generally mean turn the network off… There are folks out there documenting ‘good’ devices for this, as the producers of the parts never do, though many of them seem to be in German (which with their historically high energy cost probably makes sense).

  10. I wonder if somethink like this could be done in something even less power hungry like an esp.
    And then you could disable the NIC of the server when suspended, and repower it by using a GPIO to push the servers power button. NIC’s on real pc’s don’t exactly run powerless.

    1. I did exactly this years ago with ESP8266 wired parallel to power switch. Magic udp packet to wake. Might have actually been featured here,

      Only issue recently was that usb power for Wemos was coming from the PC itself, so when I added a smart plug to power off completely, usb power was not restored after full power loss until first boot, making a chicken-egg problem. Bios setting helped there.

  11. Use a low end Netgate firewall. Create a VPN tunnel to the firewall and configure the WOL package. Works great when I’m not in the office or too lazy to push the power button.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.