Live data from Hacker News

Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

maximiliangolla.com

1–10 of 230 posts

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#2
A Python script that automatically suspends the server, when it is not used, and another script to wake the server up again, in case there is work to do. To my surprise I could not find any out-of-the-box solution, so I thought, it is a worthwhile effort to write about it.

Currently, the server is primarily used for two things: - Plex Media Streaming (remotely) - Time Machine Backups (locally)

To monitor Plex activities, we access the local Plex API and for Time Machine we simply monitor any file access at /mnt using "lsof." In case there has been no activity for 15 consecutive minutes, the server goes to sleep. (Nobody streams, pausing a video doesn't count as activity, and no backup is running.) A Web server on a Raspberry Pi hosts a website that obtains the current state of the home server provided via the Home Assistant REST API. In case the server sleeps, and I like to backup or stream something, I can wake the server using a simple button press that sends a magic packet using a wakeonlan Perl script.

GitHub: https://github.com/m33x/wol-plex-server

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#4
post #3

>Why isn't this build into every major operating system by now? Because no desktop OS besides MacOS can handle Sleep with any semblance of competency. >Why isn't this the default See above.

I've never had any issues with stand-by on Windows.

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#5
post #3

>Why isn't this build into every major operating system by now? Because no desktop OS besides MacOS can handle Sleep with any semblance of competency. >Why isn't this the default See above.

I've never had any issues with stand-by on Windows.

ah so you're a new windows user

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#6
Interesting solution.

I wonder if you could make the 'wake up' a bit more advanced.

Run tcpdump or something similar on the Pi, with a filter set for inbound packets to the media server on ports that Plex or Time Machine uses. If it sees those packets, send the WoL magic packet.

This might not work if your switch does proper port isolation - but you could perhaps add port mirroring or something like that.

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#7
post #3

>Why isn't this build into every major operating system by now? Because no desktop OS besides MacOS can handle Sleep with any semblance of competency. >Why isn't this the default See above.

I've never had any issues with stand-by on Windows.

Windows in particular is notorious as of late for brutally draining the battery while Sleeping[1].

[1]: https://www.youtube.com/watch?v=OHKKcd3sx2c

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#8
>Why isn't this the default (or at least a configuration option)?

Because 1) you still need a second machine to wait for incoming requests, 2) in a server there's no general way to check if the server is serving requests or not. Plex happened to provide an API that specifically does what you needed, but you had to resort to a bit of a hack for Time Machine. This is unlike a desktop context, where you can check if the user has moved the mouse or pressed a key in the last N minutes. And 3) because the delay of waiting for the server to wake back up is undesirable.

>Seriously, there is soooo much potential to save energy in IT.

I don't think so. For VPS instances it doesn't matter, and for internal servers it's almost certainly more efficient to virtualize a bunch of services onto a single box, if there's multiple servers idle most of the time.

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#9
post #5

Earlier quoted context omitted.

I've never had any issues with stand-by on Windows.

ah so you're a new windows user

The majority of Sleep/Suspend/Hibernate related issues I had on Windows were related to it either not sleeping at all, or waking up at the wrong time.

Annoying when it's a laptop that you've just unplugged and stuffed into your backpack, and you're wondering why there's now an oven on your back. Less fatal for a desktop when the goal is to save power.

For linux, sleep/suspend is also pretty reliably good in my experience.

Re: Saving Energy: Home Server That Automatically Suspends to RAM and Wakes Up Again

#10
Thanks to Valve's focus on improving Linux suspend on AMD hardware, suspend recently started working reliably on my desktop. It now suspends automatically, and I set up a button on my phone to send a wake-on-lan packet. My phone is always VPNed to home, so I can wake it up from anywhere.

For my server, I just focused on choosing very power efficient hardware. I use a passively cooled baytrail SoM.

Post reply on HN