Hi Team,
i have a virtual machine, that collects log-files twice a day and is not needed during the rest of day, so in order to save rescources on the host a cronjob starts the VM in the morning and evening and hibernates it after 3 hours.
But usually the log-file collection is done after less then an hour, but sometimes takes up to 2.5 hours, so it would be nice if the VM can put itself back to sleep after the job is done.
I thought about creating a "flag-file" in a shared directory and a process on the post that wait for this file to appear and then saving the state of the VM, but that is unreliable and puts an additional process on the host, using resources…
So is there a way for a VM to signal to the hypervisor that it should be hibernated?
Thank you very much in advance for your help.
Frank/2
How can a VM put itself to sleep
-
- Site Moderator
- Posts: 20965
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: How can a VM put itself to sleep
I use the flag-file process on windows hosts, communicating between computers over networks, using VBscript for monitoring the presence/absence of the flag files. It is not a hard load on the host, especially if you put a delay between the presence tests. Even a 1-second delay has a very easy load.
If Guest Additions are installed, 'Vboxmanage guestproperty get/set' on the host, and 'vboxcontrol guestproperty get/set' on the guest can pass strings that can be monitored for commands.
Vboxcontrol in the guest also has commands to 'suspend', 'savestate', and 'poweroff', but they appear to be "not implemented" yet.
So you'll be stuck with a "flag file" or guestproperty monitoring script.
If Guest Additions are installed, 'Vboxmanage guestproperty get/set' on the host, and 'vboxcontrol guestproperty get/set' on the guest can pass strings that can be monitored for commands.
Vboxcontrol in the guest also has commands to 'suspend', 'savestate', and 'poweroff', but they appear to be "not implemented" yet.
So you'll be stuck with a "flag file" or guestproperty monitoring script.
-
- Posts: 2
- Joined: 28. Apr 2020, 17:22
- Primary OS: MS Windows 10
- VBox Version: OSE other
- Guest OSses: Oracle Linux
Re: How can a VM put itself to sleep
I wasn't aware that there is a VBoxControl tool for the VM! Thank you very much for pointing me to that.
You are correct, the function savestate,suspend and poweroff are not implemented, but there is the function writelog:
[root@odsee11 ~]# /usr/bin/VBoxControl writelog "You can shut me down."
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 5.2.12
(C) 2008-2018 Oracle Corporation
All rights reserved.
This will generate the following entry in the vbox.log-file:
04:27:34.675556 VMMDev: Guest Log: You can shut me down.
A little script, that runs every 5 Minutes and tests the log-file for this entry and invokes VBoxManage saveState and - done!
Even the log-file rotation is done by VirtualBox!
You are correct, the function savestate,suspend and poweroff are not implemented, but there is the function writelog:
[root@odsee11 ~]# /usr/bin/VBoxControl writelog "You can shut me down."
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 5.2.12
(C) 2008-2018 Oracle Corporation
All rights reserved.
This will generate the following entry in the vbox.log-file:
04:27:34.675556 VMMDev: Guest Log: You can shut me down.
A little script, that runs every 5 Minutes and tests the log-file for this entry and invokes VBoxManage saveState and - done!
Even the log-file rotation is done by VirtualBox!
-
- Site Moderator
- Posts: 20965
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: How can a VM put itself to sleep
That should work. Guestproperty get/set can do similar without having to parse the log file, but whatever floats the boat...