Add initial libvirt hook scripts
authorKristian Fiskerstrand <kf@sumptuouscapital.com>
Sat, 28 May 2016 20:40:43 +0000 (22:40 +0200)
committerKristian Fiskerstrand <kf@sumptuouscapital.com>
Sat, 28 May 2016 20:40:43 +0000 (22:40 +0200)
hooks/hook.d/gentoo03/prepare.d/01-default.sh [new symlink]
hooks/hook.d/prepare.d/01-default.sh [new file with mode: 0755]
hooks/lxc [new file with mode: 0755]

diff --git a/hooks/hook.d/gentoo03/prepare.d/01-default.sh b/hooks/hook.d/gentoo03/prepare.d/01-default.sh
new file mode 120000 (symlink)
index 0000000..3ac5c6e
--- /dev/null
@@ -0,0 +1 @@
+../../prepare.d/01-default.sh
\ No newline at end of file
diff --git a/hooks/hook.d/prepare.d/01-default.sh b/hooks/hook.d/prepare.d/01-default.sh
new file mode 100755 (executable)
index 0000000..ba2f5a4
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo TEST.$1
diff --git a/hooks/lxc b/hooks/lxc
new file mode 100755 (executable)
index 0000000..6f9d2e3
--- /dev/null
+++ b/hooks/lxc
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+HOOK_DATA=$(/bin/cat)
+HOOK_GUEST_NAME=${1}
+HOOK_PHASE=${2}
+HOOK_ACTION=${3}
+
+#
+# phases are:
+# prepare - before any resource labelling
+# start   - after libvirt has finished labeling all 
+#           resources, but has not yet started the guest
+# started - after the LXC process has successfully started up:
+# stopped - before libvirt restores any labels
+# release - after libvirt has released all resources
+# reconnect- libvirtd daemon restart 
+#
+#
+HOOK_LOCATION="/etc/libvirt/hooks/hook.d"
+
+function run_scripts(){
+       DIR=${1}
+       for x in ${DIR}/*; do
+       echo $x
+       if [[ -x ${DIR}/${x} ]]; then
+               echo -n ${HOOK_DATA} | ${DIR}/${x} ${HOOK_GUEST_NAME} ${HOOK_PHASE} >&2
+       fi
+       done;
+}
+
+if [[ -d ${HOOK_LOCATION}/${HOOK_GUEST_NAME}/${HOOK_PHASE}.d ]]; then
+       run_scripts ${HOOK_LOCATION}/${HOOK_GUEST_NAME}/${HOOK_PHASE}.d
+elif [[ -d ${HOOK_LOCATION}/${HOOK_PHASE}.d ]]; then
+       run_scripts ${HOOK_LOCATION}/${HOOK_PHASE}.d
+fi
+