Created
October 9, 2020 14:10
-
-
Save dln/7daaab19df260d169c063b89550805a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # Exmple hook script for PVE guests (hookscript config option) | |
| # You can set this via pct/qm with | |
| # pct set <vmid> -hookscript <volume-id> | |
| # qm set <vmid> -hookscript <volume-id> | |
| # where <volume-id> has to be an executable file in the snippets folder | |
| # of any storage with directories e.g.: | |
| # qm set 100 -hookscript local:snippets/hookscript.pl | |
| use strict; | |
| use warnings; | |
| print "GUEST HOOK: " . join(' ', @ARGV). "\n"; | |
| # First argument is the vmid | |
| my $vmid = shift; | |
| # Second argument is the phase | |
| my $phase = shift; | |
| if ($phase eq 'pre-start') { | |
| # First phase 'pre-start' will be executed before the guest | |
| # ist started. Exiting with a code != 0 will abort the start | |
| print "$vmid is starting, doing preparations.\n"; | |
| # print "preparations failed, aborting." | |
| # exit(1); | |
| } elsif ($phase eq 'post-start') { | |
| # Second phase 'post-start' will be executed after the guest | |
| # successfully started. | |
| print "$vmid started successfully.\n"; | |
| } elsif ($phase eq 'pre-stop') { | |
| # Third phase 'pre-stop' will be executed before stopping the guest | |
| # via the API. Will not be executed if the guest is stopped from | |
| # within e.g., with a 'poweroff' | |
| print "$vmid will be stopped.\n"; | |
| } elsif ($phase eq 'post-stop') { | |
| # Last phase 'post-stop' will be executed after the guest stopped. | |
| # This should even be executed in case the guest crashes or stopped | |
| # unexpectedly. | |
| print "$vmid stopped. Doing cleanup.\n"; | |
| } else { | |
| die "got unknown phase '$phase'\n"; | |
| } | |
| exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment