Triggering LXC/VM ordered shutdown from NUT

Dultas

New Member
Mar 13, 2024
2
0
1
Looking for some advice in case I've missed something.

I'm looking to configure NUT to shutdown LXC/VMs that are non crucial when the notification for 'ONBATT' occur. The remaining I would shut down on 'LOWBATT'.

To do this I'm looking for a way to get a list of lxc / vm that don't have a tag on them ie "crucial". I'm aware of qm list and pct list but I'm not seeing any way of filtering them based on tags. I'd like to avoid having to parse the list of all the conf files if I can, if not it's probably not that difficult a script but having a command that could just spit out the list would be even easier.

Additionally if the power comes back 'ONLINE' I'm curious if there is a simple way to trigger the on boot ordered sequence of startups for everything that is start at boot?

Thanks for any info in advance.
 
# For machines that could be shutdown here is the listing but you could instead of "echo" do "pct stop"/"qm stop" at end also:
for lxc in $(pct list|grep running|awk '{print $1}');do pct config $lxc|grep tags|grep crucial >/dev/null || echo $lxc ;done
for vm in $(qm list|grep running|awk '{print $1}');do qm config $vm|grep tags|grep crucial >/dev/null || echo $vm ;done

# For machines that should start here is the listing but you could instead of "echo" do "pct start"/"qm start" at end also:
for lxc in $(pct list|awk 'FNR>1 {print $1}');do pct config $lxc|grep onboot >/dev/null && echo $lxc ;done
for vm in $(qm list|awk 'FNR>1 {print $1}');do qm config $vm|grep onboot >/dev/null && echo $vm ;done
 
Last edited:
  • Like
Reactions: _gabriel
@waltar thanks for the reply. I was hoping for a cleaner solution but imagined awk / and grep would come into it. I'll probably need to get the list and process it further so I can shutdown in order. Should be fairly easy in perl script.
 
Should be fairly easier with a emergency power generator or a solar panel with batteries for your pve so you don't need scripting for power down and up later your vm's and lxc's also ... :cool: ^^
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!