Answer the question
In order to leave comments, you need to log in
What is the correct way to shut down KVM guest OSes?
Good afternoon! There is a server (centos 7) in the office + ups must 3000VA with a console COM port. I connected the whole thing to each other and installed nut. The server has kvm, which runs windows and linux machines. Actually the task: when the light is turned off, the oops gives a signal that it is running on batteries, then when the discharge reaches a minimum, it sends the nut-monitor command, which in turn executes the script for turning off the machines and turning off the host machine. Actually, the whole problem is that it is the windows of the machine that receive the shutdown signal and freeze and do not want to turn off. What was done:
set group policies in windows to shut down the server without logging in and not displaying a window on how to shut down the server. I set the value ShutdownWarningDialogTimeout=00000001 in the registry
did not help
set settings in /etc/sysconfig/libvirt-guests file
ON_SHUTDOWN=shutdown
PARALLEL_SHUTDOWN=1
SHUTDOWN_TIMEOUT=90
[Must]
driver = blazer_ser
port = /dev/ttyS0
desc = "server"
offdelay = 300
ondelay = 0
RUN_AS_USER nut
MONITOR [email protected] 1 monuser password master
MINSUPPLIES 1
SHUTDOWNCMD "sudo /etc/ups/shutdown.sh --shutdown"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/ups/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 0
[monuser]
password = password
actions = SET
instcmds = ALL
upsmon master
#!/bin/bash
shutdown_quests(){
LIST_VM=`virsh list | grep running | awk '{print $2}'`
TIMEOUT=90
DATE=`date -R`
LOGFILE="/etc/ups/kvm-quest-shutdown.log"
if ; then
touch $LOGFILE
#echo "$LOGFILE created" 1>&2
elif ; then
echo "$DATE : Start script" >> $LOGFILE
fi
for activevm in $LIST_VM
do
PIDNO=`ps ax | grep $activevm | grep kvm | cut -c 1-6 | head -n1`
echo "$DATE : Shutdown : $activevm : $PIDNO" >> $LOGFILE
virsh shutdown $activevm > /dev/null
COUNT=0
while [ "$COUNT" -lt "$TIMEOUT" ]
do
ps --pid $PIDNO > /dev/null
if [ "$?" -eq "1" ]
then
COUNT=110
else
sleep 5
COUNT=$(($COUNT+5))
fi
done
if [ $COUNT -lt 110 ]
then
echo "$DATE : $activevm not successful force shutdown" >> $LOGFILE
virsh destroy $activevm > /dev/null
fi
done
}
note(){
echo -e "--------------------------------------------------------\n"
echo -e "\nYou need usage script with arguments: --reboot ot --shutdown:\n\n $0 --shutdown\n"
exit 1
}
reboot_node(){
reboot
}
shutdown_node(){
systemctl poweroff -i
}
if [ $# -ne 1 ]; then
note
fi
for i in "[email protected]" ; do
if ; then
shutdown_quests
reboot_node
break
fi
if ; then
shutdown_quests
shutdown_node
break
fi
done
Defaults !requiretty
nut ALL=(ALL) NOPASSWD: /etc/ups/shutdown.sh
Answer the question
In order to leave comments, you need to log in
Empirically, it was found that when window server 2008 shut down, open user programs waited for shutdown, but since the command virsh shutdown vm
sends a shutdown signal on behalf of the "system" user, which does not have rights to shut down the server with a forced shutdown of terminal users, it is necessary :
1. Give the necessary rights to the "system" account to shut down (done in group policies)
or 2. install a kvm
agent that will shut down the server
. Which option is convenient for you and use it, I settled on installing the agent
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question