Wake on LAN script

rinseaid

Renowned Member
Jan 8, 2012
11
6
68
I wanted to share a configuration I've been using for a little while to enable Wake on LAN with a KVM guest. I've got a guest with an NVIDIA GPU passed through for gaming, which I use in combination with Gamestream on an NVIDIA Shield Android TV box. My goal was to reduce power consumption, and prevent some weirdness I have previously seen with long running VMs with GPU passthrough.

This script was heavily based on the great work by dmacias over at the unRAID forums: https://lime-technology.com/forum/index.php?topic=38289.0

I modified the script to look for WOL magic packets on UDP ports 7 and 9, and UDP port 47998 which is used by Gamestream. The script collects the destination MAC address, and searches for Proxmox configuration files in /etc/pve/qemu-server containing the specified MAC address. Once found, it checks if the VM is already running by issuing a qemu-status command, and if not running, a qm start <vmid> command is issued.

In my use case, I set my Windows VM to hibernate after 15 minutes. I can't recall where, but I've read that sleep is not recommended with KVM VMs, or perhaps just those using GPU passthrough. In any case, hibernation works well for my needs. Within seconds of selecting a game from the NVIDIA Shield, the WOL packet is sent and the Windows VM starts to boot and return to the hibernated state. All up, it takes about 30 seconds to boot.

Usage:
  1. Unzip contents of attachment to a directory of your choosing. I use /root/scripts
  2. Create folder /var/log/proxmoxwol - a file named proxmoxwol.log will be created and all logs sent here. Additionally, the below init script will log into this directory.
  3. To start the service at boot, copy (and rename) the proxmoxwol.init file from the zip contents to '/etc/init.d/proxmoxwol', set as executable with 'chmod +x proxmoxwol' - and then enable with 'update-rc.d proxmoxwol defaults'.
  4. Make sure to modify the cmd and int variables as required in /etc/init.d/proxmoxwol for your script location and bridged network adapter.
  5. To rotate the logs, which get quite large in my network due to frequent WOL requests, copy (and rename) proxmoxwol.logrotate to file '/etc/logrotate.d/proxmoxwol'.
  6. Install pcap with `apt-get install python-libpcap`
  7. Either reboot or issue '/etc/init.d/proxmoxwol start' and check the above mentioned log file for status and/or errors.
Hope this is useful to someone.
 

Attachments

  • proxmoxwol.zip
    4.1 KB · Views: 187
Last edited:
Thanks for posting this along with great instructions. I'm using this now on my server.

One small hitch I ran into, the MAC address testing in your Python script is case sensitive. My Shield sends a packet with lowercase MAC address for whatever reason which didn't work at first. I made an ugly patch (attached).

Just issue `patch < proxmoxwol_patch.txt` where your proxmoxwol.py file is located.
 

Attachments

  • proxmoxwol_patch.txt
    408 bytes · Views: 98
Sorry to bring an old post back from the dead, but I love the script, just implemented it today. At the moment, I have to set my VMs with passed through cards to automatically log in if I want to just dive in and start using gamestream to stream my entire desktop to my shield.

I spent some time looking for ways to secure the sign in process and create a sort of "canned remote Windows login solution" that would run on the client without me taking any specific extra steps like loading up VNC, but that seems like a heck of a lot of work, so maybe someone here would know better than I if this can be done.

What if we make the gamestream service run before login? If someone can find the specific executable that runs NVIDIA's gamestream, a scheduled task could be used to start the service, using an existing user's credentials, before sign in. After the devices have been paired once, there's no need to enter the pairing code on the desktop, so that shouldn't present an issue. From there the GFE could be used to call remote desktop for the sign in process. Thoughts? I want a gamestream VDI so bad!
 
Sorry again for bumping this up... does anyone have that zip file and can reupload?
Somehow the first post attachment doesn‘t work.
 
Hi - I went ahead and uploaded the files to https://github.com/rinseaid/proxmox-wol

Sorry I haven't looked at this thread in some time as I'm no longer using Proxmox, but I went ahead and also included ;piod's patch- thanks!

For TheFunk's question, I did look into this a little bit and couldn't find any way to run the GeForce Experience/Streaming service under the SYSTEM context.
 
Thanks a lot! It still works in 5.1!

I forked the repo and will try to add WoL for containers and perhaps even „Sleep on LAN“ on a 2nd magic packet.
 
In case anyone wants it, I added WoL for LXC in my fork (gotta mask links, I'm too new to post GitHub links ;)):
github.com/djraw/proxmox-wol
or as direct dl
github.com/djraw/proxmox-wol/archive/master.zip

I tried writing a systemd service but gave up on it. ;)
Also Sleep on LAN will have to wait as it doesn't use magic packets.. I use this PHP for that on Win machines
github.com/sciguy14/Remote-Wake-On-LAN-Server
 
Last edited:
Can I use this script to wake up the Proxmox host rather than the VMs or Containers? If not what changes do we need to make? Does this support 5.x by default or do we need additional packages?

Thanks in advance.
Regards,
Bobby Thomas
 
Can I use this script to wake up the Proxmox host rather than the VMs or Containers?
No, this script just checks for so called magic packets and generates commands to start VMs and Containers. It can‘t run when the host is switched off, as no OS is running in that case.

The host itself shouldn‘t need any script or packages to be able to wake up on LAN magic packets. You should be able set this up in the hosts BIOS. I recommend checking the support website or documentation of the hosts manufacturer.

The script works for 5.x by default, but just starts up VMs and LXCs like I mentioned before. It should work for coming versions as well as long as the command line options to start VMs and LXCs don‘t change.
 
Last edited:
Ok, I thought it need support in BIOS and in OS. I will check that and update here tomorrow.

Thank you R.A.W
regards,
Bobby Thomas
 
I came across this script and it had errors related getting the VMID, just appended a line to fix that.

Here is a zipfile updated proxmoxwol.py for anyone who comes across this post.
 

Attachments

  • proxmoxwol.zip
    2.1 KB · Views: 29
It is broken with Proxmox Version 7.0 however fixed it after running

Bash:
wget http://mirrors.kernel.org/ubuntu/pool/universe/p/python-libpcap/python-libpcap_0.6.4-1_amd64.deb && dpkg -i python-libpcap_0.6.4-1_amd64.deb
 
You can send api call since proxmox 6.2.
It's a good alternative than the wol service running and you can do more stuff as well. start/stop/reset for exemple
 
You can send api call since proxmox 6.2.
It's a good alternative than the wol service running and you can do more stuff as well. start/stop/reset for exemple

So how does one do it the API way does it work with say guacamole? See my current setup is ssh/vnc/rdp via guacamole are setup to send a wol packet and then connect.
 
Hello, any updates on this topic? I always facing following issue: active (exited) . does any one here, who has working/updated files?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!