How to use new hookscript feature?

Vengance

Renowned Member
May 21, 2016
271
12
83
34
Hi,

I just noticed, that hookscripts have been implemented in the newest version of Proxmox.
Unfortunately I couldn't find any documentation about it.
 
Thanks, looks like it's not possible to set one in the UI?
Would be aswesome, if I could add a hook script when cloning a template.

Edit: I think I missunderstood something, they won't be executed in the VM, right?
I was looking for a way, to run commands via Cloudinit after the VM has booted.
 
Heads up to anyone who comes across this thread, the following is all of the documentation of hook scripts and how to attach to vm's.
10:10, attaching to vm's

You can add a hook script to VMs with the config property hookscript.
# qm set 100 --hookscript local:snippets/hookscript.pl
It will be called during various phases of the guests lifetime. For an example and documentation see the example script under /usr/share/pve-docs/examples/guest-example-hookscript.pl.


16.8, hookscripts
You can specify a hook script with option --script. This script is called at various phases of the backup process, with parameters accordingly set. You can find an example in the documentation directory (vzdump-hook-script.pl).

This is pretty sparse if you ask me.. Especially since I've seen multiple references from mod's to it.
 
  • Like
Reactions: copec
For anyone else coming across this thread. Here are the commands I used to setup a hookscript for a VM.

Code:
#snippets folder didn't exist so I created it
mkdir /var/lib/vz/snippets

#Copied the template to the folder
cp /usr/share/pve-docs/examples/guest-example-hookscript.pl /var/lib/vz/snippets/secon-hookscript.pl

#modified the perl script with the applicable commands
nano /var/lib/vz/snippets/secon-hookscript.pl

# Made it executable
chmod +x /var/lib/vz/snippets/secon-hookscript.pl

#Set it to the applicable VM
qm set 102 --hookscript local:snippets/secon-hookscript.pl
 
Can I use multiple hookscripts simultaneously?

(One is a bash shell script for GPU passhtrough, the other is written in Perl, for virtio-fs.)
 
Last edited: