post-install-hook-examples
A library of five example hook scripts for var_post_install, which runs a script on the host after a container has been created.
post-install-hook-examples.sh is not a tool you execute. Its own header says "This file is NOT meant to be executed as-is". It is a collection of five example hooks for the var_post_install setting of the container engine. It is not listed on the website.
Source: tools/pve/post-install-hook-examples.sh. The hook itself is run by pve/backend.func in the core repository.
How a hook runs
var_post_install holds the absolute path of a script on the Proxmox VE host. After a container script has created the container, the engine runs it on the host:
bash "${var_post_install}"| Aspect | Behaviour |
|---|---|
| Where | On the Proxmox VE host, not inside the container. |
| Output | Captured in /var/log/community-scripts/post-install-<CTID>.log. |
| Path does not exist | Error message and a dialog. The container stays as created; the hook did not run. |
| Hook exits non-zero | A dialog shows the exit code and the last log lines. The container is not rolled back. |
The engine passes these variables to the hook:
| Variable | Content |
|---|---|
APP | Display name, for example Vaultwarden |
NSAPP | Lowercase slug, for example vaultwarden |
CTID | Container ID |
IP | IPv4 address of the container |
HN | Hostname |
STORAGE | Storage of the root filesystem |
BRG | Bridge, for example vmbr0 |
Use an example
- Open the source file and copy one block between its
BEGINandENDmarkers into a new file on the host, for example/opt/community-scripts/hooks/notify.sh. - Edit the
CONFIG (edit me)section of the block. - Point
var_post_installat the file: in/usr/local/community-scripts/default.vars, in an app's.varsfile, or in the Advanced Settings dialog titled "POST-INSTALL HOOK (HOST)".
var_post_install=/opt/community-scripts/hooks/notify.shThe comment block at the top of the example file still names /root/.community-scripts/default.vars and "Step 28". The engine reads /usr/local/community-scripts/default.vars, and the dialog is step 31 of 32.
Making the file executable is optional, because it is started with bash <path>.
The examples
| # | Name in the file | What it does | You must edit |
|---|---|---|---|
| 1 | minimal-logger.sh | Appends one line per created container (timestamp;ctid;app;hostname;ip;bridge;storage) to /var/log/community-scripts/created-lxcs.log. | Nothing |
| 2 | discord-gotify-notify.sh | Sends a Discord embed and a Gotify push with the container's details. | DISCORD_WEBHOOK, GOTIFY_URL, GOTIFY_TOKEN, GOTIFY_PRIORITY |
| 3 | auto-pool-tags-backup.sh | Adds the container to a Proxmox pool (creating it if needed), merges extra tags into the existing ones, registers a DNS record through the Pi-hole API and starts a vzdump snapshot backup. | TARGET_POOL, EXTRA_TAGS, BACKUP_STORAGE, PIHOLE_HOST, PIHOLE_PASSWORD, DNS_DOMAIN |
| 4 | inject-ssh-and-monitoring.sh | Pushes a public key to /root/.ssh/authorized_keys in the container, installs the Beszel agent there as beszel-agent.service and sends one push to an Uptime Kuma monitor. | ADMIN_KEY, BESZEL_HUB_URL, BESZEL_AGENT_KEY, UPTIME_KUMA_PUSH_BASE |
| 5 | per-app-router.sh | One hook for all apps that branches on NSAPP: databases get more resources, a pool and a Prometheus target; *arr apps get tags and a webhook call; web apps are registered at a reverse proxy; everything else gets a node-exporter target. | DEFAULT_DNS_SUFFIX, PROM_FILE_SD_DIR, and the endpoints inside the case branches |
Things to know before copying
- Example 3: set
BACKUP_STORAGE=""to skip the initial backup. It writes the Pi-hole password in clear text into the hook file. - Example 4:
pct pushoverwrites/root/.ssh/authorized_keysin the new container. The Beszel binary is downloaded from the project's latest GitHub release inside the container. - Example 5: the endpoints
http://media-hub.<suffix>/hooks/arr-addedandhttp://traefik.<suffix>/api/dynamic-addare placeholders for services of your own; they do not exist by default. The Prometheus helper needspython3on the host. The*arrbranch replaces the container's tags withcommunity-script;media;arr-stack. - The header recommends
set -euo pipefail,|| trueon best-effort steps, and keeping hooks idempotent because they run again when you recreate a container.