[pve-devel] [PATCH guest-common v3 1/2] add exec_hookscript to GuestHelpers

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Jan 30 08:06:59 CET 2019


On Tue, Jan 29, 2019 at 04:28:41PM +0100, Dominik Csapak wrote:
> 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 | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/PVE/GuestHelpers.pm b/PVE/GuestHelpers.pm
> index c326812..8327dcb 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,35 @@ 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});

this is still missing the safeguard of checking for the proper volume
type.

> +    if (!$hookscript || ! -x $hookscript) {
> +	my $errmsg = "hookscript $hookscript not found or not executable\n";

this check is slightly different than the one in guest-common #2 - maybe
they can be unified by adding $noerr to the check method?

or wrap in eval and die/warn here based on $stop_on_error..

would also get us the vtype check for free ;)

> +
> +	if ($stop_on_error) {
> +	    die $errmsg;
> +	} else {
> +	    warn $errmsg;
> +	}
> +	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
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list