[pve-devel] [PATCH guest-common 1/1] add exec_hookscript to GuestHelpers
Fabian Grünbichler
f.gruenbichler at proxmox.com
Wed Jan 23 15:40:23 CET 2019
On Mon, Jan 21, 2019 at 09:44:34AM +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 | 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});
please check the vtype here as well to make sure we are still
referencing a 'script', just to prevent a source of future bugs.
> + if (!$hookscript || ! -x $hookscript) {
> + warn "hookscript $hookscript not found or not executable\n";
IMHO this should be a die if $stop_on_error ? e.g., such hookscripts
might be used to setup firewall rules or something like that, and if a
script is referenced in the config, we probably don't want to ignore
that it is missing.. this can be made configurable as well by making
hookscript a property string and adding a flag to control such
behaviour (and setting $stop_on_error accordingly)?
> + 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