Is there any way to make KVM automatically restart any VMs that have been shut down due to power failure? Here is my scenario: I run a small VM tank, mostly with development VMs on it. I now have a VM that is set to autostart on system boot, which works. I have installed apcupsd on that VM, reading from the daemon on the host, and configured to shut down when battery reaches 75%. The host will shut down when the battery reaches 15%. My question is, if power returns during this window (i.e. the host stays up), can I restart the VM that was shut down? I know I could hard-code a call to 'virsh start [VM name]' but I am looking to start any VM flagged as 'autostart', somewhat like doing 'mount -a' to mount all defined filesystems. Is this possible?
Linux – libvirt – Restart VMs after return from power failure
apcupsdkvm-virtualizationlibvirtlinuxvirsh
Related Solutions
Currently when one of the two UPS dies, the doshutdown event is triggered, and executes the default script via apccontrol. The doshutdown script ignores the second UPS, as they are not event-connected, and proceed normally with the shutdown.
In order to have the doshutdown events somewhat connected, the two instances of apcupsd need a specifically customized configuration file. The difference will reside in the directory from which the events scripts have to be executed.
Main properties of first ups, in /etc/apcupsd/apcupsd.ups0.conf
SCRIPTDIR /etc/apcupsd/ups0
UPSNAME ups0
DEVICE /dev/ups0
PWRFAILDIR /etc/apcupsd/ups0
NOLOGINDIR /etc/apcupsd/ups0
NISPORT 3551
EVENTSFILE /var/log/apcupsd.0.events
And for the ups1, in /etc/apcupsd/apcupsd.ups1.conf
SCRIPTDIR /etc/apcupsd/ups1
UPSNAME ups1
DEVICE /dev/ups1
PWRFAILDIR /etc/apcupsd/ups1
NOLOGINDIR /etc/apcupsd/ups1
NISPORT 3552
EVENTSFILE /var/log/apcupsd.1.events
Each scriptdir should get a copy of the default scripts.
We want to customize the doshutdown script, which will not directly shutdown the machine, but has to check if the other UPS is still on, or is in shutdown mode.
At the top of the doshutdown script, we could add something like
for ups0
if [ ! -f /tmp/ups1.is.down ]
then
touch /tmp/ups0.is.down
exit 99
fi
for ups1
if [ ! -f /tmp/ups0.is.down ]
then
touch /tmp/ups1.is.down
exit 99
fi
the status 99 has a special meaning, that tells apccontrol to stop the action in progress. The five lines check if the other UPS-down-file has been created ; if no, the down-file is created for the ups being down, and exits. If yes, meaning the other UPS is down, this one is getting down as well, thus the script should continue and shutdown the machine.
The files /tmp/usp[01].is.down
indicate if the ups[01] is currently down.
Important: the init.d start script of apcupsd should remove these files, if they have been created in a previous session:
rm -f /tmp/usp[01].is.down
Finally, the directories created above, /etc/apcupsd/ups[01] should be given access to the apcupsd user (or to whichever relevant user running the instances).
chown -R apcupsd /etc/apcupsd/ups[01]
Please have a look at the detailed documentation.
edit fixed the /tmp/ups[01].is.down
names, the .is
was missing.
You can use the <qemu:commandline>
domain XML tag.
For example:
<qemu:commandline>
<qemu:arg value='-option-rom'/>
<qemu:arg value='path/to/my.rom'/>
</qemu:commandline>
For more information, read here
Best Answer
On my RHEL6 and CentOS6 that is established by creating a symbolic link to VM XML description in
/etc/libvirt/qemu/autostart/
:If you want to avoid setting up links manually:
virsh autostart <domain>