]>
git.proxmox.com Git - pve-docs.git/blob - examples/guest-example-hookscript.pl
3 # Exmple hook script for PVE guests (hookscript config option)
4 # You can set this via pct/qm with
5 # pct set <vmid> -hookscript <volume-id>
6 # qm set <vmid> -hookscript <volume-id>
7 # where <volume-id> has to be an executable file in the snippets folder
8 # of any storage with directories e.g.:
9 # qm set 100 -hookscript local:snippets/hookscript.pl
14 print "GUEST HOOK: " . join(' ', @ARGV). "\n";
16 # First argument is the vmid
20 # Second argument is the phase
24 if ($phase eq 'pre-start') {
26 # First phase 'pre-start' will be executed before the guest
27 # ist started. Exiting with a code != 0 will abort the start
29 print "$vmid is starting, doing preparations.\n";
31 # print "preparations failed, aborting."
34 } elsif ($phase eq 'post-start') {
36 # Second phase 'post-start' will be executed after the guest
37 # successfully started.
39 print "$vmid started successfully.\n";
41 } elsif ($phase eq 'pre-stop') {
43 # Third phase 'pre-stop' will be executed before stopping the guest
44 # via the API. Will not be executed if the guest is stopped from
45 # within e.g., with a 'poweroff'
47 print "$vmid will be stopped.\n";
49 } elsif ($phase eq 'post-stop') {
51 # Last phase 'post-stop' will be executed after the guest stopped.
52 # This should even be executed in case the guest crashes or stopped
55 print "$vmid stopped. Doing cleanup.\n";
58 die "got unknown phase '$phase'\n";