post-start
phase. Documentation and where to find the example hookscript: https://pve.proxmox.com/pve-docs/chapter-pct.html#_hookscripts# dmesg | grep apparmor
[ 4091.454217] audit: type=1400 audit(1665995133.442:20): apparmor="STATUS" operation="profile_load" profile="/usr/bin/lxc-start" name="lxc-101_</var/lib/lxc>" pid=10356 comm="apparmor_parser"
[ 4092.391168] audit: type=1400 audit(1665995134.378:21): apparmor="DENIED" operation="mount" info="failed flags match" error=-13 profile="lxc-101_</var/lib/lxc>" name="/" pid=10471 comm="mount" flags="rw, remount"
[ 4092.391577] audit: type=1400 audit(1665995134.378:22): apparmor="DENIED" operation="mount" info="failed flags match" error=-13 profile="lxc-101_</var/lib/lxc>" name="/" pid=10472 comm="mount" flags="rw, remount, relatime"
hookscript: <string>
Script that will be exectued during various steps in the containers lifetime.
Yes, the hookscript is executed on the host.Is there any means to execute scripts on the host and have the results placed in the guest LXC during first boot of the container?
It's a content type for a file-base storage in Proxmox VE, so on the host.Where is the snippets folder - in the host or guest LXC?
You put it in theWhere in the LXC template / VMID.conf / dab.conf do we put the hookscript in?
snippets
folder on your Proxmox VE storage. Ideally, the storage is shared between nodes, so the hookscript is accessible from all nodes when the container migrates. If the storage is not shared, you still need to ensure that the script is available on each node respectively.This sets the hookscript for the container.Executing from host using pct is listed here.
The ID is passed to the hookscript as an argument. See the example hook script.Please note that we do not yet know the VMID when the template was made and the container was created when operating from within the container.
} elsif ($phase eq 'post-start') {
# Second phase 'post-start' will be executed after the guest
# successfully started.
print "$vmid started successfully.\n";
my $node = `cat /etc/hostname`;
system("pct exec $vmid -- /root/updateinfo.sh $vmid $node");
} elsif ($phase eq 'pre-stop') {
updateinfo.sh
is a script in the container putting the info somewhere appropriate.snippets
folder in the storage section of the Web GUI in the node and having named the script as lxc_hookscript.pl and made it 755 permissions, other than cli mode with pci set... where in the container (from template) do we put in the this script name?This script is not executed on first startup only, but on every startup, it's not for DAB.Having allowedsnippets
folder in the storage section of the Web GUI in the node and having named the script as lxc_hookscript.pl and made it 755 permissions, other than cli mode with pci set... where in the container (from template) do we put in the this script name?
Otherwise, are all scripts in the snippets folder executed for all containers so that the name of the hookscript is immaterial or must it be hardcoded as hostscript.pl?
Otherwise, how and where in the DAB Makefile should this script be referenced?
How do we make sure that the said script is executed on first startup only.
pct exec
command tries to execute (in my example that was /root/updateinfo.sh
, but it can be any other binary or script).pct set <ID> --hookscript ...
command just sets the hookscript in the container's configuration. You can only set one hookscript at a time, but you can re-use the hookscript for multiple containers. If there is a hookscript
set in the containers configuration, it will be executed during the various phases like post-start
.pct set VMID --hookscript ...
only and that too after the first boot is over.pci set --hookscript ...
is:root@pr72:~# pct start 101
root@pr72:~# pct enter 101
# If "pct mount 101" is executed, it must be reverted with "pct unmount 101" before shutdown/remove of LXC guest.
# There is no UnMount menu entry in PVE-7.x GUI
# Upload /root/updateinfo.sh and set permissions to 755
# root@sqlamp:/# cd ~
# root@sqlamp:~# ./updateinfo.sh 101
root@sqlamp:~# exit
root@pr72:~# cd /var/lib/vz/snippets
root@pr72:/var/lib/vz/snippets# ./lxc_hookscript.pl 101 post-start
GUEST HOOK: 101 post-start
101 started successfully.
/var/lib/vz/snippets/lxc_hookscript.pl
in the host (default storage) and at /root/updateinfo.sh
in the DAB templated LXC guest (VMID 101).