summaryrefslogtreecommitdiff
path: root/libvirt/hooks/qemu
diff options
context:
space:
mode:
authorSeth Flynn <[email protected]>2021-11-18 18:18:06 -0500
committerSeth Flynn <[email protected]>2021-11-18 18:18:06 -0500
commitdbf050fb9e98c35596008b4404687cda9f35b13c (patch)
treebe355367cf74c574065ca6def19a39c4d51f9f79 /libvirt/hooks/qemu
parent46449c8361a7fb72d9dcfe55a0f75f73f45cacf5 (diff)
add libvirt hooks
Diffstat (limited to 'libvirt/hooks/qemu')
-rwxr-xr-xlibvirt/hooks/qemu34
1 files changed, 34 insertions, 0 deletions
diff --git a/libvirt/hooks/qemu b/libvirt/hooks/qemu
new file mode 100755
index 0000000..155ec57
--- /dev/null
+++ b/libvirt/hooks/qemu
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# Author: Sebastiaan Meijer ([email protected])
+#
+# Copy this file to /etc/libvirt/hooks, make sure it's called "qemu".
+# After this file is installed, restart libvirt.
+# From now on, you can easily add per-guest qemu hooks.
+# Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name.
+# For a list of available hooks, please refer to https://www.libvirt.org/hooks.html
+#
+
+GUEST_NAME="$1"
+HOOK_NAME="$2"
+STATE_NAME="$3"
+MISC="${@:4}"
+
+BASEDIR="$(dirname $0)"
+
+HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME"
+
+set -e # If a script exits with an error, we should as well.
+
+# check if it's a non-empty executable file
+if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH"] && [ -x "$HOOKPATH" ]; then
+ eval \"$HOOKPATH\" "$@"
+elif [ -d "$HOOKPATH" ]; then
+ while read file; do
+ # check for null string
+ if [ ! -z "$file" ]; then
+ eval \"$file\" "$@"
+ fi
+ done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)"
+fi
+