5

I am running KVM as virtualization engine.

Is there a way to make QEMU/libvirt run a script on the host when a guest is shutdown from within (shutdown -h now)?

I want to be able to run some custom clean-up tasks when a guest is stopped.

Daniele Testa
  • 661
  • 4
  • 10
  • 18

1 Answers1

5

libvirt provides the possibility to use hooks for specific system management:

At present, there are three hook scripts that can be called:

    /etc/libvirt/hooks/daemon

    Executed when the libvirt daemon is started, stopped, or reloads its configuration

    /etc/libvirt/hooks/qemu

    Executed when a QEMU guest is started, stopped, or migrated

    /etc/libvirt/hooks/lxc

    Executed when an LXC guest is started or stopped
dawud
  • 15,096
  • 3
  • 42
  • 61
  • For a practical example: [Run script in the host when starting virtual machine with virt-manager](https://unix.stackexchange.com/a/426213/154671) (Unix.SE). – Marc.2377 Feb 24 '18 at 02:17