[pve-devel] [PATCH guest-common 1/1] add exec_hookscript to GuestHelpers
Dominik Csapak
d.csapak at proxmox.com
Mon Jan 21 09:44:34 CET 2019
this can be called from qemu-server/pve-container to execute a hookscript
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/GuestHelpers.pm | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/PVE/GuestHelpers.pm b/PVE/GuestHelpers.pm
index c326812..1b81e6d 100644
--- a/PVE/GuestHelpers.pm
+++ b/PVE/GuestHelpers.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use PVE::Tools;
+use PVE::Storage;
# We use a separate lock to block migration while a replication job
# is running.
@@ -23,4 +24,29 @@ sub guest_migration_lock {
return $res;
}
+sub exec_hookscript {
+ my ($conf, $vmid, $phase, $stop_on_error) = @_;
+
+ return if !$conf->{hookscript};
+ my $storecfg = PVE::Storage::config();
+ my $hookscript = PVE::Storage::path($storecfg, $conf->{hookscript});
+ if (!$hookscript || ! -x $hookscript) {
+ warn "hookscript $hookscript not found or not executable\n";
+ return;
+ }
+
+ eval {
+ PVE::Tools::run_command([$hookscript, $vmid, $phase]);
+ };
+
+ if (my $err = $@) {
+ my $errmsg = "hookscript error for $vmid on $phase: $err\n";
+ if ($stop_on_error) {
+ die $errmsg;
+ } else {
+ warn $errmsg;
+ }
+ }
+}
+
1;
--
2.11.0
More information about the pve-devel
mailing list