Running hooks when incoming migration is finished

danielb

Renowned Member
Jun 1, 2018
231
63
68
38
Bordeaux (france)
Hi.

On some VM, I need to exec a hook script when an incoming live migration is over (and another one when an outgoing live migration is over). In my case, it's to redirect public IP from my hoster (Online.net) to the new node where the VM is running, and updating routes to setup ARP proxying.

Until now, I managed to do this using a self written daemon which listens to sockets creation/deletion in /var/run/qemu-server with inotify, and fire the scripts. The problem I have is that since the latest versions (I guess since qemu 3.0), the migrate socket is unlinked nearly immediatly, while the migration is still running, so I cannot detect when the incming migration is finished anymore.

I'd like to remove this daemon, and use the hooks PVE recently added. But I only see pre-start, post-start, pre-stop and post-stop hooks. As a migration can take un unkown amount of time (from a few sec to several minutes, depending on the link speed, and the VM activity), I don't want to migrate the IP when the qemu process is started on the new node, but only when the migration is finished, to have a minimal downtime. Is there a way to do this somehow ?

Are more hooks planned ? (ideally, I'd like to have pre-migrate-in, pre-migrate-out, post-migrate-in and post-migrate-out)

Thanks,
Daniel
 
  • Like
Reactions: rholighaus
Are more hooks planned ? (ideally, I'd like to have pre-migrate-in, pre-migrate-out, post-migrate-in and post-migrate-out)
if there is enough need, yes. for now you could start your daemon in the 'post-start' hook and check if the vm has a 'migrate' lock (e.g. via qm config)
 
  • Like
Reactions: rholighaus
Hi Dominik, can you give me a hint how to detect migrate lock on LXC in such case?
of the top of my head (no guarantees for correctness) :

Code:
pct config ID | grep lock | grep migrate

has output if it has a migrate lock (also the exit code is 0 if found, !0 otherwise)
 
yes the same as for vms (pre-start, post-start, pre-stop, post-stop)

It looks like pre-stop is not supported for LXC at this moment.
post-stop doesn't seem to see the migration lock in the config, it's already gone.
Neither does a pre-start on the machine where it migrated to.
 
Last edited:
if there is enough need, yes. for now you could start your daemon in the 'post-start' hook and check if the vm has a 'migrate' lock (e.g. via qm config)

Could you kindly provide us with documentation how to configure e.g. a post-start hook for a vm?
I cannot find anything in the documentation apart from the announcement that this is now supported since 5.4
Thank you!
 
Could you kindly provide us with documentation how to configure e.g. a post-start hook for a vm?
check the example script /usr/share/pve-docs/examples/guest-example-hookscript.pl
 
I now tried to check for the lock: migrate in the configuration but it looks it is only there AFTER the post-stop hook has been executed and is already removed BEFORE the pre-start hook is executed:

On migration source node:
Code:
/var/lib/vz/snippets/pve-hook called with pve_number=119 and hook_type=pre-stop
Container configuration for 119:
arch: amd64 cores: 1 hookscript: local:snippets/pve-hook hostname: penta-gateway memory: 512 net0: name=eth0,bridge=vmbr0,gw=192.168.100.1,hwaddr=6A:5A:7C:F9:56:98,ip=192.168.100.119/24,type=veth onboot: 1 ostype: debian rootfs: rpool:subvol-119-disk-0,size=20G swap: 256
/var/lib/vz/snippets/pve-hook called with pve_number=119 and hook_type=post-stop
Container configuration for 119:
arch: amd64 cores: 1 hookscript: local:snippets/pve-hook hostname: penta-gateway memory: 512 net0: name=eth0,bridge=vmbr0,gw=192.168.100.1,hwaddr=6A:5A:7C:F9:56:98,ip=192.168.100.119/24,type=veth onboot: 1 ostype: debian rootfs: rpool:subvol-119-disk-0,size=20G swap: 256

On migration target node:
Code:
/var/lib/vz/snippets/pve-hook called with pve_number=119 and hook_type=pre-start
Container configuration for 119:
arch: amd64 cores: 1 hookscript: local:snippets/pve-hook hostname: penta-gateway memory: 512 net0: name=eth0,bridge=vmbr0,gw=192.168.100.1,hwaddr=6A:5A:7C:F9:56:98,ip=192.168.100.119/24,type=veth onboot: 1 ostype: debian rootfs: rpool:subvol-119-disk-0,size=20G swap: 256
/var/lib/vz/snippets/pve-hook called with pve_number=119 and hook_type=post-start
Container configuration for 119:
arch: amd64 cores: 1 hookscript: local:snippets/pve-hook hostname: penta-gateway memory: 512 net0: name=eth0,bridge=vmbr0,gw=192.168.100.1,hwaddr=6A:5A:7C:F9:56:98,ip=192.168.100.119/24,type=veth onboot: 1 ostype: debian rootfs: rpool:subvol-119-disk-0,size=20G swap: 256
 

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!