Tuesday, November 1, 2022

Home Server / WallX / TouchPortal / Power Saving Kludge


Upfront: this is a bit of a kludge, and I'll be looking for a better option, as soon as I can find one. But it thought me things...

Anyway, with the ever-increasing price of electricity, I was wondering if I could not simply switch off my home server upon command. In the past, I used a timed-out, which worked fine, but there are other users in my household, and they're not always computer-savvy.


Unfortunately, Windows doesn't have something like 'wake up the server when I need it'. You could have your server wake up on *any* traffic, but it seems there's always some device messing around, thus it would never shut off.

Quite the conundrum...

Here's my approach. For now... (And yes, this is going to get very nerdy.)

Tools used

  • SysInternals' psshutdown.exe
  • TouchPortal
  • WallX
  • cmdow.exe
  • waitwindow.exe

A. Server schedule

1. On my home server I used Task Scheduler to launch three tasks at specific times:

2. Six days a week I switch the server to standby at 01:00, using SysInternals' ps_shutdown command. To do so I call a batch file that contains:

  1. C:\software\power_shortcuts\psshutdown.exe -d -t 0

This means that if someone used the server, it will automatically shutdown at night, and will only restart whenever somebody needs it.

3. On Sunday morning I do a full restart at 01:00. I'm running LMS (SqueezeBox server) on it, and have it rescan the database etc. at around 01:30. Then at 02:00 I've scheduled some updates (Windows etc.) and at 02:30, it goes to sleep again.

Experience has shown that my server needs a reboot every now and then. Some PC's work fine without a reboot, and some don't.

B. Windows wakeup

1. If somebody wants to use the server from their PC, I've written a little tool called Wakiewakie, which is nothing but a pinger and WOL sender. It shows some extra information and a progress bar. Especially the latter helps my dear users to stay patient...

So, on every PC there's an icon to wake up the server, and in some cases I've installed a little batch file that starts Wakiewakie first, and then launches Kodi, SqueezeLite-X or whatever.

C. Media player wakeup

The hardware SqueezeBox players support WOL, and that works most of the time. The NVidia Shield has no default WOL, but I've added a WOL app.

Finally, my users know where to find the power button of the server. If it blinks they press it one time, and voila.

In other words, if all software tools fail, they have to walk to the storage where the server is gathering dust, and use their dirty fingers to prod the machine to life. Maybe I should try to add a Homematic button... even more senseless, I guess 😏

D. Putting the server to sleep

That's a little nastier. I don't want panicky users who grumble when their movie is halted because the server decided to do a power down on its own. Modern hardware is too fast, and the 'do not sleep' options in LMS and Plex are unreliable. And if someone's streaming from the server to Kodi he / she is completely ignored.

So, normally, the server goes to sleep at 01:00, and that's it. Worst case is that it takes a few hours of power. I did replace the power supply for a more efficient model, and that absolutely helps, but yeah. I'm wasting a few hours of power, and that isn't good. Now my household typically starts using the thing around 17:00 or so, so that's eight hours lost.

However, I regularly work from home and may be playing some music before going out. Or, I might simply be done with hobby / work and go to bed. And being the last one going to sleep, I might want to put the server to sleep.

I could walk down towards the storage, but where's the fun in that? 😁 (And yes, I've tried to tell my users to push the button to bring my server to sleep when they leave the house... and yet to no avail.)

However, getting the server to sleep isn't that simple. There are some commands, and you can mess with the registry etc. but it's not always working, and one more Windows update and it no longer does. Now my users pretty much don't care, but I do.

WallX to the rescue

I'm using a little tool called WallX for managing wallpapers, and as it's running anyway I've modified it a bit to detect the existence of a semaphore file. (I plan to add some IP communication later, so the last century kludge with a semaphore file is no longer required.)

So, if WallX detects a specific file in the temp folder, then it will delete that file, then launch the batch file that puts the server to sleep. This is WallX running on the server, looking for the semaphore file.

Of course, that will only work if someone copies that file there. At this moment, that someone would be me...

E. Putting my workstation in standby

I have a tendency to switch it off, but when I temporary do something else I might sleep it, so I added a few buttons / shortcuts / scripts to make setting it to sleep easier.

First of all, I created a sleep batch file that checks if I haven't got OBS or VirtualBox running. VirtualBox doesn't like the host in standby, and OBS blocks going standby.

  1. rem close OBS
  2. cmdow obs* /cls
  3. waitwindow obs* forever close

  4. rem close one VM
  5. cmdow "legacy - windows*" /cls
  6. waitwindow "legacy - windows*" forever close

  7. rem close another VM
  8. cmdow "sponge10 - windows*" /cls
  9. waitwindow "sponge10 - windows*" forever close

  10. rem go to sleep
  11. psshutdown.exe -d -t 0

So, calling the batch file above takes care of sleeping my PC, but not my server (that will be next).

To start that batchfileI 've got a shortcut on my desktop. made a link to it in TouchPortal, and used the keyboard software to launch it when pressing the extra '1' key in the top left corner of my keyboard. Now I have no excuse anymore not to put my machine to sleep.

F. Putting the server AND my work station in standby

That's pretty much the same as above, but this time I added copying the semaphore file.

  1. cmdow obs* /cls
  2. waitwindow obs* forever close

  3. cmdow "legacy - windows*" /cls
  4. waitwindow "legacy - windows*" forever close

  5. cmdow "sponge10 - windows*" /cls
  6. waitwindow "sponge10 - windows*" forever close

  7. if not exist \\media6\drive_c$\temp\semaphore_power goto done
  8. copy \\media6\drive_c$\temp\semaphore_power \\media6\drive_c$\temp\semaphore_power_sleep

  9. :done
  10. psshutdown.exe -d -t 0

Of course, I created a shortcut, added a TouchPortal button, and assigned keyboard key '2' to launch the batchfile.

G. Retrieving the server status

Now we're entering nerd territory. I wanted a button in TouchPortal that showed me the state of my server, and wanted to use it as a kind of server on / off toggle as well.

Unfortunately, TouchPortal is a bit lacking on certain options and events, so again I had to resort to a kludge using a semaphore file. For another application I already implemented a 'heartbeat' inside WallX, so I switched that on. (This is the WallX running on my work station.) This means the semaphore file is updated every 60 seconds.

In TouchPortal I check if the file has been updated, and if so I check if I can retrieve a webpage from my home server. My home server does run TinyWeb as a kind of intranet server for other purposes, so I had something to retrieve, and a semaphore file to act as a kind of repeating trigger (click image to enlarge).

Now, once every 60 seconds, TouchPortal checks if the server is alive. If it is, the button lights up green, if it isn't it lights up red. Pretty useless but fun 😎

See that red icon above the purple 'sleep all' button? Yeah. The server was off when I wrote this.

H. Nerdiness Squared

Then, even more useless, I created a 'server on server off' script, and added that to this indicator. So, hitting it once switches the server on, hitting it once more switches it off, and it reports the state of the server (after a delay of 0..120 seconds).

Completely useless, but it works 😁

I'll have to look into adding some kind of TPC/IP based communication, which is faster, has less overhead, and more elegant, but for now the current solution works.

Here's the ugly script that I launch when touching the server state button (Media6 / is my home server):

  1. ping -n 1 -w 100>nul || goto wakeup

  2. rem file check may take up to 30 seconds

  3. if exist \\media6\drive_c$\temp\semaphore_power goto sleep

  4. :wakeup

  5. wakiewakie.exe history adapter 192.168.*.* router server mac xx:xx:xx:xx:xx:xx color $FFFFFF $000080 linger 1200 retry 500 history
  6. net use \\media6 /user:xxxxxx xxxxxx 

  7. goto done

  8. :sleep

  9. copy \\media6\drive_c$\temp\semaphore_power \\media6\drive_c$\temp\semaphore_power_sleep

  10. rem it can take up to two minutes before touchportal shows the correct server state

  11. timeout 60
  12. goto done

  13. :done
  14. exit

No comments:

Post a Comment