Shutdown (Poweroff) VM via terminal session

devis

New Member
Mar 2, 2023
24
2
3
Hello everyone, our cluster is using HA

however, I noticed that at the moment when the shutdown or reboot command is sent through the terminal, the HA starts to actively turn on the machine

Please tell me how to get around this or how to increase the ON timeout to turn on the machine
 
Hello everyone, our cluster is using HA

however, I noticed that at the moment when the shutdown or reboot command is sent through the terminal, the HA starts to actively turn on the machine

Please tell me how to get around this or how to increase the ON timeout to turn on the machine
Hi,
do you mean that you are trying to power off a VM but the HA services restart the VM?
Well, that is exactly what the HA manager is for, it tries to keep the VM in its required state. If you don't want a VM to be managed by HA for maintenance or other reasons, you can always set the state to ignored, so the VM is not covered by the HA services anymore.

Please have a look at the docs https://pve.proxmox.com/pve-docs/pve-admin-guide.html#_configuration_15
 
Not quite so, I need HA to manage the machine, but I would like that the commands sent (shtutdown or poweroff) from the virtual machine would not be processed in this case by the HA manager,

Example 1: the machine is on, I send a command inside the poweroff machine, I expect HA to put the machine into the stopped state

Example: 2: the machine is turned on, I kill the kvm process on the hypervisor, I expect HA to turn on the machine
 
Not quite so, I need HA to manage the machine, but I would like that the commands sent (shtutdown or poweroff) from the virtual machine would not be processed in this case by the HA manager,

Example 1: the machine is on, I send a command inside the poweroff machine, I expect HA to put the machine into the stopped state

Example: 2: the machine is turned on, I kill the kvm process on the hypervisor, I expect HA to turn on the machine
In that case you will have to use the ha-manager set vm:<VMID> --state stopped command on the Proxmox VE host to set the new desired VM state. Otherwise the HA manager cannot know that the VM should be in that state.
 
Is it possible to somehow set Timeout for HA, I have a hook that sends this status, but the hook works slower than HA, and it turns out that when sending a command from the HA virtual machine, it instantly starts turning it on and then the hook turns on and stops it, however, the hook can work negatively if the kvm process of the virtual machine is killed, what should I do in this case?


Hook
Perl:
#!/usr/bin/perl

use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

my $vmid = shift;
my $phase = shift;

if ($phase eq 'pre-start') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'post-start') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'pre-stop') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'post-stop') {
    #system("/usr/sbin/qm stop $vmid");
    system("/usr/sbin/ha-manager set $vmid --state stopped");
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} else {
    die "Got unknown phase '$phase'\n";
}

exit(0);
 
Is it possible to somehow set Timeout for HA, I have a hook that sends this status, but the hook works slower than HA, and it turns out that when sending a command from the HA virtual machine, it instantly starts turning it on and then the hook turns on and stops it, however, the hook can work negatively if the kvm process of the virtual machine is killed, what should I do in this case?


Hook
Perl:
#!/usr/bin/perl

use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

my $vmid = shift;
my $phase = shift;

if ($phase eq 'pre-start') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'post-start') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'pre-stop') {
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} elsif ($phase eq 'post-stop') {
    #system("/usr/sbin/qm stop $vmid");
    system("/usr/sbin/ha-manager set $vmid --state stopped");
    #system("/usr/bin/python /usr/bin/vm_cache_clean.py $vmid");
} else {
    die "Got unknown phase '$phase'\n";
}

exit(0);
You are trying to use the HA manager for a use case it is not intended for. So please explain, what is your actual use case? Why not set the state to stopped when required?
 

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!