[update] Wake (and other) on LAN for VMs (v0.3)

ojaksch

Renowned Member
Oct 11, 2015
189
43
68
Germany/Earth
(EDITED)
I ever wondered why there's no solution to startup VMs by WOL 'til now, so I helped myself and wrote a bash script that I want to share. I called this baby dosthol (Do something on LAN) which will do other tasks some day, i.E. remote shutdown and others.
Maybe someone will find this small tool useful too. Feel free to comment, copy, extend ...

Copy dosthol.sh to /usr/local/bin and dosthol.service to /etc/systemd/system . Start (and enable) the service, then send a MagicPacket/MAC of a VM which can be a qemu or lxc one. The VM should start then.

Dependencies: PVE v4.x, vim, socat (got trouble with both netcat regarding broadcast).
 
Last edited:
Project finished. Enclosed daemon, client and systemd service file.
dosthol ist now able to wakeup, shutdown, poweroff (stop), suspend, resume and reset qemu and lxc VMs (reset n/a with lxc).

Was a funny project :cool: Have fun!
 

Attachments

  • dosthol-0.2.zip
    2.7 KB · Views: 149
Update time!
- dosthol.service: Fixed a typo which led service to fail (call of dosthol.sh instead of dosthold.sh, leftover from v0.1)
- Client: Parameter parsing, help extended, some beautifyings and option to send MagicPacket to a specific IP or subnet
 

Attachments

  • dosthol-0.3.zip
    3.1 KB · Views: 127
  • Like
Reactions: onepamopa
Hallo

leider funktioniert es nicht (WOL) wenn man von einer VM Snapshots angelegt hat.
Sobald ich den Snapshot gelöscht hab startet die VM per WOL



Mar 17 08:01:42 pve systemd[1]: dosthol.service: Service hold-off time over, scheduling restart.
Mar 17 08:01:42 pve systemd[1]: Stopped dosthol (Do something on LAN).
Mar 17 08:01:42 pve systemd[1]: Started dosthol (Do something on LAN).
 
leider funktioniert es nicht (WOL) wenn man von einer VM Snapshots angelegt hat.
Sobald ich den Snapshot gelöscht hab startet die VM per WOL
Schön, dass tatsächlich jemand damit arbeitet :)
Ich schaue mir das einmal an; das habe ich seinerzeit gar nicht bedacht, geschweige denn getestet - daher Danke für den Hinweis. Ich nehme an, dass Deine VM eine "echte" VM ist, also kein LXC-Container?
 
Woll, Problem gefunden und gefixt. Mein Skript schaut nach der benötigten MAC-Adresse und verarbeitet das gefundene Ergebnis in einer Variable. Wenn aber ein Snapshot vorhanden ist, schreibt PVE in die betreffende Config Zeuch für die erstellten Snapshots - und damit taucht als Suchergebnis mehrfach die MAC auf, womit die Variable nicht mehr passten konnte.

Anbei die aktuelle Version. Viel Spaß beim Testen und Benutzen!
 

Attachments

  • dosthol-0.5.zip
    3.2 KB · Views: 134
Vielen Dank für den fix. Hat wunderbar geklappt. Jetzt kann ich endlich über Homebridge Siri sagen welche VM er starten soll :)
 
jap

ich habe ne Homebridge mit WOL Plugin auf ner Raspberry Pi am laufen
der dann per Siri die VMs vom Proxmox Server aufweckt.

ohne dein Script weiss ich nicht wie ich sonst die VMs aufwecken kann
 
Hallo,

ich plane etwas ähnliches, mir ist jedoch noch nicht ganz klar wie das script funktionieren soll. Ich habe 2 VM die ich gerne per WOL wecken möchte: Einmal Linux, einmal Win10. Auf beiden verwenden virtio Netzwerkkarten mit eigenen IP`s und der Gast Agent läuft. Habe jetzt schon ein wenig rumgespielt aber ich bekomme es aktuell nicht zum laufen.

Somit 3 IP´s: Server, LinuxVM, WindowsVM
Schicke ich nun das WOL Paket and die Server IP mit der MAC der VM und das Skript leitet das weiter? Muss ich eine spezielle Netzwerkkarte auswählen?

Abgeschickt wird das Paket bei mir von einem FHEM das auf einer dritten Instanz auf dem gleichen Server läuft...
 
...schau mal in mein ZIP-File. Das Skript dostholc.sh ist das clientseitige (Bash-) Skript. Der Client sendet die Befehle (Wake, Shutdown etc.).
dosthold.sh (und das dazugehörige systemd-File) ist der Daemon, der auf dem PVE läuft und auf Kommandos eines Client (dostholc) wartet.

dostholc erwartet als Parameter -f <FUNKTION> und -m <MAC_DER_VM> und sendet die Kommando-Sequenz als Broadcast-Message in das IP-Subnet. Der Daemon dosthold auf dem PVE "sieht" das, wertet es aus und führt das gewün
schte Kommando per qm (KVM) oder pct (LXC) aus. Es wird also keine VM direkt angesprochen.
WerWoWas dostholc aufruft ist völlig Schnuppe, solange nicht dort oder dazwischen eine Firewall alles wegblockt ;)

Insgesamt also eine kleine und primitive Lösung, die wenig bis nichts drumherum erfordert.

(dostholc.sh benötigt die Programme xxd und socat, dosthold.sh nur socat)
 
Oh schönes ding, es läuft :)

Es lag daran das gawk nicht installiert war:

Code:
/dosthol# service dosthol status
● dosthol.service - dosthol (Do something on LAN)
   Loaded: loaded (/etc/systemd/system/dosthol.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-06-07 13:00:37 CEST; 45s ago
 Main PID: 26681 (dosthold.sh)
    Tasks: 3 (limit: 4915)
   Memory: 1.5M
      CPU: 6ms
   CGroup: /system.slice/dosthol.service
           ├─26681 /bin/bash /usr/local/bin/dosthold.sh
           ├─26688 socat -u udp-recv:9,readbytes=102 -
           └─26689 xxd -u -p -c 102

Jun 07 13:00:37 pm systemd[1]: Started dosthol (Do something on LAN).
Jun 07 13:00:37 pm dosthold.sh[26681]: /usr/local/bin/dosthold.sh: line 27: gawk: command not found

Jetzt muss ich mir noch überlegen wie ich das in FHEM rein bekomme, das benutze ich als "Schaltzentrale".

Vielen Dank!
 
  • Like
Reactions: onepamopa
Prima, geht doch. Freut mich. Und gawk war nicht installiert, bzw. fehlte? Ich mach mir mal 'ne Notiz in die Header des dosthol, dass das benötigt wird. Der Nächste kommt bestimmt und fragt auch :)
 
Ja das fehlte tatsächlich, hatte es direkt vom Proxmox Host ausgeführt. Daraufhin hat es auf Anhieb funktioniert.
 
Hallo,

bei mir funktioniert das Tool auch, super Danke!!!

Zur Info: gawk musste auf dem pve noch installiert werden.
 
Hello,
I had an idea to create a command called toggle for a mac address.

Basically I want to avoid spamming my PVE with switch on's or wakeups if the VM is already alive.

perhaps a trigger like "dostholc.sh -m AA: BB: CC: DD: EE: FF -f toggle"
could do the following:
A: Get the VMID from mac address (I think we already do this) in your script)
B: Check status off VM ID.
C: If stopped: Start it, If suspended resume it.


I.have made some changes to the script by adding a -f toggle.

This toggle switch will grab the VM status and resume it if suspended or paused, wake it up if stopped/hibernated.
and hibernate (suspend -to-disk 1) if it is running.

Please see attachment.
 

Attachments

  • dosthol-0.6.zip
    3.4 KB · Views: 239
Last edited:

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!