Skip to main content
Community Scripts logo
Skip to Content
Tools & Add-onsPVE Tools

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}"
AspectBehaviour
WhereOn the Proxmox VE host, not inside the container.
OutputCaptured in /var/log/community-scripts/post-install-<CTID>.log.
Path does not existError message and a dialog. The container stays as created; the hook did not run.
Hook exits non-zeroA dialog shows the exit code and the last log lines. The container is not rolled back.

The engine passes these variables to the hook:

VariableContent
APPDisplay name, for example Vaultwarden
NSAPPLowercase slug, for example vaultwarden
CTIDContainer ID
IPIPv4 address of the container
HNHostname
STORAGEStorage of the root filesystem
BRGBridge, for example vmbr0

Use an example

  1. Open the source file and copy one block between its BEGIN and END markers into a new file on the host, for example /opt/community-scripts/hooks/notify.sh.
  2. Edit the CONFIG (edit me) section of the block.
  3. Point var_post_install at the file: in /usr/local/community-scripts/default.vars, in an app's .vars file, or in the Advanced Settings dialog titled "POST-INSTALL HOOK (HOST)".
var_post_install=/opt/community-scripts/hooks/notify.sh

The 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 fileWhat it doesYou must edit
1minimal-logger.shAppends one line per created container (timestamp;ctid;app;hostname;ip;bridge;storage) to /var/log/community-scripts/created-lxcs.log.Nothing
2discord-gotify-notify.shSends a Discord embed and a Gotify push with the container's details.DISCORD_WEBHOOK, GOTIFY_URL, GOTIFY_TOKEN, GOTIFY_PRIORITY
3auto-pool-tags-backup.shAdds 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
4inject-ssh-and-monitoring.shPushes 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
5per-app-router.shOne 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 push overwrites /root/.ssh/authorized_keys in 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-added and http://traefik.<suffix>/api/dynamic-add are placeholders for services of your own; they do not exist by default. The Prometheus helper needs python3 on the host. The *arr branch replaces the container's tags with community-script;media;arr-stack.
  • The header recommends set -euo pipefail, || true on best-effort steps, and keeping hooks idempotent because they run again when you recreate a container.