How to shut down or savetate VMs before the host is turned off by the UPS shutdown signal?

Discussions related to using VirtualBox on Linux hosts.

How to shut down or savetate VMs before the host is turned off by the UPS shutdown signal?

Postby Cube3 » 20. Aug 2019, 02:24

Hello everyone! Sorry for my English, I used a translation tool

I am running multiple VMs (Virtualbox 5 and 6) on Debian 8 and **I need the VMs to shut down or savetate before the host is turned off by the UPS shutdown signal** (Or Poweroff buton or shutdown command).

I have created a script that starts the VMs as a service

/etc/systemd/system/vncservice.service
Code: Select all   Expand viewCollapse view
    [Unit]
    Description=VBox Virtual Machine %i Service
    Requires=systemd-modules-load.service
    After=systemd-modules-load.service
   
    [Service]
    User=usuario
    Group=vboxusers
    ExecStart=/home/scripts/script.start.sh
    ExecStop=/home/scripts/script.stop.sh
    RemainAfterExit=true
    KillMode=none
   
    [Install]
    WantedBy=multi-user.target

Another that starts them

/home/scripts/script.start.sh
Code: Select all   Expand viewCollapse view
    #!/bin/bash
    echo "Starting VMs...."
    export DISPLAY=:1
    /usr/bin/vboxmanage startvm VM1 --type gui
    /usr/bin/vboxmanage startvm VM2 --type gui

And another that turns them off

/home/scripts/script.stop.sh
Code: Select all   Expand viewCollapse view
    #!/bin/sh -
    export DISPLAY=:1
    echo "Apagando VMs...."
    /usr/bin/VBoxManage controlvm VM1 acpipowerbutton
    /usr/bin/VBoxManage controlvm VM2 acpipowerbutton

The script works on host power on, but it doesn't turn them off in time, the host shuts down before the VMs, I don't know how to delay the host shutdown

Any suggestions or another way to do this?
Cube3
 
Posts: 1
Joined: 30. Jul 2019, 06:31

Re: How to shut down or savetate VMs before the host is turned off by the UPS shutdown signal?

Postby socratis » 20. Aug 2019, 05:20

Cube3 wrote:it doesn't turn them off in time, the host shuts down before the VMs, I don't know how to delay the host shutdown

I don't see this as a VirtualBox problem, but as a host-shutdown-procedure problem. I'll say that I'm not Debian-anything master, I'm going to simply pose a couple of points to hopefully steer you in the right direction.

I assume that the UPS is receiving a power-down trigger and issues a shutdown command on the host. I'd start from there to see if you could modify the shutdown scripts/commands and add a delay of sorts, or a 'ps' control on the VBoxSVC, a conditional that checks for and waits until specific processes have ended.

I can think of a gazillion programs that have to terminate properly to avoid a corruption during shutdown, so there's got to be an option out there. For example a quick search for "debian UPS shutdown delay" returns (among other links) the wiki for apcupsd. I think that should be a very good starting point for you to work with.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
socratis
Site Moderator
 
Posts: 25894
Joined: 22. Oct 2010, 11:03
Location: Greece
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5


Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: No registered users and 5 guests