#!/bin/bash
#option="stop"
option="shutdown"
for vm in `sudo qm list | awk '{print $1}' | grep -v VMID`
do
echo "$option VM with ID: $vm"
command="sudo qm $vm $option"
echo "--> command: $command"
# uncomment the following line to execute the command.
#sudo $command
echo " "
done
Thanks so much for taking the time to do this. I'll definitely give it a try. I spent some time digging around Prox and found a handful of files related to 'pve-manager' but no luck finding the exact scripting. It's called as a service but it's actually not a daemon, so I was hoping to find the script. I'll try both and see how it works.To shut down VMs the following script sample might help.
I did not test it and just have thrown it together
Bash:#!/bin/bash #option="stop" option="shutdown" for vm in `sudo qm list | awk '{print $1}' | grep -v VMID` do echo "$option VM with ID: $vm" command="sudo qm $vm $option" echo "--> command: $command" # uncomment the following line to execute the command. #sudo $command echo " " done
HTH
$ systemctl cat pve-guests.service
# /lib/systemd/system/pve-guests.service
[Unit]
Description=PVE guests
ConditionPathExists=/usr/bin/pvesh
RefuseManualStart=true
RefuseManualStop=true
Wants=pvestatd.service
Wants=pveproxy.service
Wants=spiceproxy.service
Wants=pve-firewall.service
Wants=lxc.service
After=pveproxy.service
After=pvestatd.service
After=spiceproxy.service
After=pve-firewall.service
After=lxc.service
After=pve-ha-crm.service pve-ha-lrm.service
[Service]
Environment="PVE_LOG_ID=pve-guests"
ExecStartPre=-/usr/share/pve-manager/helpers/pve-startall-delay
ExecStart=/usr/bin/pvesh --nooutput create /nodes/localhost/startall
ExecStop=-/usr/bin/vzdump -stop
ExecStop=/usr/bin/pvesh --nooutput create /nodes/localhost/stopall
Type=oneshot
RemainAfterExit=yes
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
Alias=pve-manager.service
Thanks @fabian - that's exactly what I was hoping to find. Much appreciatedthere is a pve-guests service (used to be called pve-manager and still aliased) that is not a daemon, but a oneshot service called at startup (start all guests configured to start on boot) and on shutdown (shutdown all running guests):
Code:$ systemctl cat pve-guests.service # /lib/systemd/system/pve-guests.service [Unit] Description=PVE guests ConditionPathExists=/usr/bin/pvesh RefuseManualStart=true RefuseManualStop=true Wants=pvestatd.service Wants=pveproxy.service Wants=spiceproxy.service Wants=pve-firewall.service Wants=lxc.service After=pveproxy.service After=pvestatd.service After=spiceproxy.service After=pve-firewall.service After=lxc.service After=pve-ha-crm.service pve-ha-lrm.service [Service] Environment="PVE_LOG_ID=pve-guests" ExecStartPre=-/usr/share/pve-manager/helpers/pve-startall-delay ExecStart=/usr/bin/pvesh --nooutput create /nodes/localhost/startall ExecStop=-/usr/bin/vzdump -stop ExecStop=/usr/bin/pvesh --nooutput create /nodes/localhost/stopall Type=oneshot RemainAfterExit=yes TimeoutSec=infinity [Install] WantedBy=multi-user.target Alias=pve-manager.service
you can see the commands that get called on shutdown (ExecStop) - if you run them manually you might want to drop the '--no-output' though
pvesh create /nodes/{host}/stopall
works except for HA-enabled VMs.ha-manager set <sid> -state started/stopped
? If not, I can at least manually stop each HA member in my script.There is a 180 second default per VM.Is there a global parameter that sets the amount of time PVE host waits on for the Guests to properly shutdown or do we have to set that amount of time for each vm in the startup/shutdown properties of the vm?
It starts them last and shuts them down first. See the manual for more details.Does PVE shutdown VMs without startup/shutdown priority at last?
So there’s no way to change the global default and I have to increase it per-VM if necessary. Thank youThere is a 180 second default per VM.
It starts them last and shuts them down first. See the manual for more details.