What Proxmox VE hookscripts automate at guest start, stop and migration
A platform team that creates and moves guests often soon finds that the CMDB, the DNS zone and the monitoring inventory fall out of step with what is actually running. A hookscript is a small script that Proxmox VE calls at defined points in a guest's life, so that the same record updates happen every time without a person remembering them. It is worth building when the update is repeatable, when it must happen at the hypervisor level for every guest regardless of who created it, and when a missed step causes real work later, such as a stale DNS record or an unregistered host that nobody can find during an incident.
Proxmox VE is an open-source platform that runs KVM virtual machines and Linux Containers (LXC) with software-defined storage and networking on one platform. Hookscripts attach custom logic to guest lifecycle events, and they are configured per guest through the guest's settings, with the script itself stored in snippet storage on the node. Which events fire, what arguments the script receives and how the platform reacts to a non-zero exit code are behaviors that must be confirmed in the Proxmox VE administration guide for the exact version you install, because they can change between releases and should not be assumed from older examples.
Before writing anything, decide which records must change, which system owns each one, and what should happen if the external call fails. A hookscript that blocks a guest start on a slow CMDB API is a different design from one that logs the failure and lets the guest run. Test the script against a non-production guest on the same Proxmox VE version as production, and confirm how a migration event behaves on a cluster node pair you actually operate, since that path is where ordering and partial failure are easiest to miss.
How a hookscript fits into the guest lifecycle
A start, stop or migration request enters the Proxmox VE cluster through the web interface, the API or the command line. The cluster runs the hookscript at the matching phase for that event, and the script then updates an external system such as a CMDB, DNS or a monitoring tool. If the external call fails, the script must decide whether the guest action should continue, so check the script's exit handling and log output before relying on it in production.
Hookscript path from a guest action to an external system, with success and failure branches.
Which hook phase fits which automation goal
This table matches common lifecycle goals, such as registering a new guest or updating DNS after a move, to the hookscript phase that fits each one. Read each row for what the hook must do, what it must be able to reach, and what a failure would block. Confirm the exact phase names and exit-code behavior in the Proxmox VE documentation for your version before you rely on them.
| Automation goal | Hook work and reach | What a failure would block |
|---|---|---|
| Register a new guest in a CMDB | Create the configuration item after the guest is defined, reading its ID, name, node and network settings. Needs read access to guest config and write access to the CMDB API. | Inventory drift if registration is skipped. Confirm whether a failed step can stop the guest from starting in your version. |
| Pre-check before start | Validate storage availability, resource reservations or policy tags before the guest runs. Needs read access to cluster and storage state. | A failed check can prevent a start that would otherwise succeed. Decide whether this is intended and confirm the failure behavior for this phase. |
| Deregister on stop | Remove or mark the CMDB record and release any reserved addresses after the guest stops. Needs CMDB write access and the guest identifier. | Stale records or leaked IP addresses. A failure here is usually an operations issue, not a boot issue, but confirm it in your version. |
| Update DNS after a migration | Rewrite A or PTR records to the new node or address once the move completes. Needs DNS API credentials and the guest's new network details. | Clients resolve to the old location. Verify whether the migration target node can reach the DNS API during the move. |
| Record a migration event | Log source node, target node and timestamps in the audit or CMDB system. Needs read access to migration context and a log destination. | Gaps in the audit trail. Logging failures should be designed to report, not silently pass. |
| Clean up external resources after shutdown | Detach or release licences, sessions or external objects tied to the guest. Needs the same credentials used at registration. | Orphaned external objects and recurring cost. Confirm which failures stop the shutdown sequence. |
| Illustrative: sync a guest network change | Push an updated address to monitoring after a configuration change. Needs the guest's current configuration and monitoring API access. | Monitoring gaps for the guest. Confirm whether this runs in a lifecycle phase or must be triggered by your own tooling. |
How to handle hookscript failures without stranding guests
A hookscript runs inside the lifecycle of a guest, so a slow or failing external call can delay or block the operation that triggered it. A CMDB update that hangs during start can leave a VM half-started, and a DNS call that times out during migration can hold up a move between nodes. Treat every external dependency as something that will eventually be slow or unavailable, and design the hook so the guest lifecycle does not depend on that dependency being healthy. The first decision is which side of that line each action sits on.
Start with idempotency. Hooks can run more than once for the same logical event after a retry, a failed task or an operator re-running an action, so each external call should check whether its change already exists before making it. Put a hard timeout on every network call inside the script, shorter than any timeout the platform applies to the task, so the script returns on its own terms. For retries, cap the attempt count and the total elapsed time, and write the final state to a log instead of retrying indefinitely. Logs should go to a path the operations team already monitors, such as a central syslog target or a file shipped by an existing agent, not only to a file on the hypervisor that nobody reads.
Decide, per action, whether a failure should stop the operation or only raise an alert. Registering a guest in a CMDB is usually an alert-only task, because the guest can run without it. Blocking a start because a non-critical registration failed usually creates more harm than it prevents. Actions that protect data or security, such as a required approval check, may justify stopping the lifecycle step. Before you rely on either behavior, confirm in the Proxmox VE hookscript documentation for your installed version exactly what a non-zero exit code does in each phase, since the effect can differ between pre-start, post-start, pre-stop, post-stop and migration phases. Test each phase in a lab with a deliberately failing script first.
Use cases for CMDB registration, DNS and other integrations
The CMDB owner usually wants a configuration item for every guest that exists on a Proxmox VE cluster, with its owner, service, environment and the node it runs on. A start or stop hook can post the guest ID, name, current node and assigned addresses to the CMDB API, which keeps the record close to what the hypervisor reports. The hard part is identity: the CMDB needs a stable key, and the Proxmox VE guest ID is unique within a cluster but can be reused after a guest is deleted.
- Stable key: Store the cluster name plus guest ID, and a generated UUID if the CMDB supports one, so a reused ID does not overwrite an old record.
- Node field: Update the node on migration instead of creating a new item, and record the migration event as history.
- Deletion: Mark the item retired or decommissioned rather than deleting it, so audit trails stay intact.
- Ownership: Confirm who maintains the CMDB schema and who approves changes to required fields.
- Failure path: Decide whether a failed CMDB call blocks the guest or writes to a retry queue.
Confirm with the CMDB owner which fields are authoritative and which are reconciled by a scheduled job instead of the hook.
The network or DNS team typically owns zones, reverse records and IP allocation. A hook can create or update a host record when a guest starts and remove it when the guest stops or is deleted. It needs the guest name, the interface MAC or configured address, the bridge or VLAN, and the zone it belongs to. Dynamic updates are a different question from an IPAM-driven workflow, so the hook should follow whichever process the team already trusts.
- Addresses: Use the configured static address or a value from the IPAM, not an address reported by a guest that may not be running yet.
- Record lifecycle: Remove A, AAAA and PTR records on stop or delete, and check that stale records do not persist after migration.
- Migration: A guest moving between nodes on the same network usually keeps its records, but a move across VLANs may not. Confirm this per network.
- Credentials: Use a dedicated DNS update account with rights limited to the zone.
- Ownership check: Ask the network team whether the hook may write to their zones at all.
Confirm the record naming convention and TTL policy with the DNS team before writing any code.
The monitoring team needs a guest to appear in monitoring when it starts and disappear cleanly when it stops for maintenance or is removed. A hook can call the monitoring system's API to add or disable a host, set a maintenance window, or apply a template based on tags. The identifiers that matter are the guest name, the address the agent or probe uses, and any tag that selects the monitoring template.
- Maintenance windows: A planned stop should suppress alerts, and the hook should end the window when the guest starts again.
- Migration: Monitoring keyed on IP address breaks if the address changes, so key on name or an agent identity where possible.
- Alert noise: Deleting a guest without disabling its host produces false alerts that the team must clear manually.
- Tags: Keep tag names agreed with the monitoring team so that templates are applied consistently.
- Verification: Check that the new host reports data before closing the change.
Confirm with the monitoring owner which objects the hook may create and which must be created by their own provisioning process.
The security team cares about what is running, where, and who changed it. A hook can forward lifecycle events with guest ID, node, actor and timestamp to a log pipeline, or update an asset inventory used for vulnerability scanning. It should not hold broad credentials to security tooling, and it should not change the security classification of a guest without an approved process. Lifecycle events are useful evidence, but only if the logs are complete and tamper-resistant.
- Event records: Send start, stop, migrate and delete events with the cluster, guest ID, node and triggering user where available.
- Scope changes: Flag guests whose network or tag changes on migration so reviewers can check segmentation.
- Credentials: Use a scoped service identity for the hook, separate from administrator accounts.
- Retention: Confirm the log retention period with the security team before deciding where events are stored.
- Delete reconciliation: Keep the record of a deleted guest in the inventory with a retired status so scans and findings remain traceable.
Confirm with the security team which events they treat as evidence and how long they must be kept.
How to set up a hookscript on a Proxmox VE cluster
This sequence takes a hookscript from an unverified idea to a versioned, tested and attached script with confirmed behavior at each guest phase. It also leaves a documented rollback path so the team can remove the hook without disturbing guests.
Confirm the Proxmox VE version and cluster state
Record the Proxmox VE version on every node and confirm the cluster is healthy before changing anything. Check that all nodes are online, quorum is present and the configuration is in sync across the cluster. Confirm the version against the Proxmox VE FAQ support window, since a hookscript that works today must still run on a supported release. The step is done when you have a written record of versions and a clean cluster status for every node.
Choose and prepare snippet storage
Hookscripts are stored as snippets, so select a storage location that is enabled for snippet content and is available on every node that may run the guest. Confirm the exact storage setup and content types in the Proxmox VE administration guide, since storage configuration differs by backend. Verify the storage is shared or replicated to all nodes where guests can migrate. The step is done when the storage shows the snippet content type on each node and the same file path resolves on all of them.
Write and version the hookscript
Write the script against the phases documented in the administration guide, handling each phase explicitly and exiting cleanly for phases you do not use. Keep the script in version control with a tagged release, and record the target Proxmox VE version it was tested against. Have a second engineer review the script for error handling, timeouts and any credentials it uses. The step is done when the script is committed, reviewed, and its checksum or tag is recorded alongside the change ticket.
Test the script on a non-production guest
Attach the script to a test guest on a non-production node or cluster, using the same Proxmox VE version as production. Trigger every phase you rely on, including a migration between nodes, and confirm the script runs once per event without blocking the guest. Test failure paths deliberately by making the target system unreachable, so you see what the guest does when the hook fails. The step is done when each phase has a recorded result and the failure behavior matches what your change record expects.
Attach the hookscript to the target guest
Attach the tested script to the production guest using the hookscript setting documented in the administration guide, and keep the change limited to the guests in scope. Record the guest IDs, the snippet path and the time of the change. Confirm the setting appears in the guest configuration on the node where it will run. The step is done when the guest configuration lists the hook and a change record names every guest affected.
Verify each phase in logs and the target system
Trigger each lifecycle event on the attached guest and check the Proxmox VE task log, the script's own log output and the target system, such as the CMDB record or DNS entry. Compare the observed state with the expected state for start, stop and migration. Confirm that the hook's output appears on the node that actually ran the guest. The step is done when every phase has matching evidence in both the Proxmox VE logs and the target system.
Document rollback and hand over operations
Write down how to detach the hookscript, restore the previous guest configuration and revert the target system changes, and rehearse the detach on the test guest. Name the owner for script changes, the log locations and the alert or review path for hook failures. Confirm the rollback steps against the current Proxmox VE documentation for your version. The step is done when the rollback has been rehearsed once and the runbook is stored where operations staff can find it.
Security risks of running code on every guest event
A hookscript runs on the node that handles a guest event, often with root rights and access to whatever credentials it needs for the target system. The cards below cover the risks that tend to appear together in these setups, with a check for each and the team that should own the control.
Target system credentials on disk
A hookscript that registers guests in a CMDB or DNS usually needs an API token or password for that system. If the token sits in the script or a plain file next to it, anyone who can read the snippet or the node's filesystem gets that access. Check where the secret is stored, who can read it, and whether it can be rotated without editing the script. The security team or the secrets owner should hold this control, ideally backed by a dedicated secrets store.
Proxmox user managementElevated code on cluster nodes
Hookscripts execute on Proxmox VE nodes, which hold cluster configuration and guest disks. A bug or a malicious change in a hook can affect every guest on the node, not only the one that triggered the event. Check who can modify hook files, whether the script is reviewed before deployment, and whether it avoids unnecessary privileged commands. The platform or infrastructure team owns the node, and the change process should cover hooks like any other host change.
Shared snippet storage
Hookscripts are stored as snippets on storage that cluster members can reach. When several administrators can edit the same snippet location, a change by one person runs on every node at the next event, with no second review. Confirm which accounts can write to the snippet storage, whether changes go through version control, and whether a named reviewer approves each change. Ownership belongs to the platform team, with the security team reviewing access rights.
Over-privileged integration accounts
It is common to reuse an administrator account for a hook because it is the quickest way to make the call work. That account can then delete guests or change DNS zones far beyond what registration requires. Check that the account has only the rights for the specific action, such as creating a host record, and that it is separate from human admin accounts. The identity or IAM team should define the role and review it on a schedule.
Injection through guest metadata
Hooks often read the guest name, tags, description or network settings and pass them into shell commands or API payloads. A guest name containing shell characters or unexpected fields can change what the script does. Check that the script validates inputs against an allow list, quotes arguments, and never builds commands by string concatenation. Application or platform engineers who write the hook own this control, and a test with unusual names should be part of acceptance.
Audit trail for hook changes
A hook can create records in other systems without any entry in the Proxmox VE task log that names the script or its outcome. Without logging on both sides, an unexpected DNS record or CMDB entry is hard to trace back to a hook. Confirm that each hook writes its actions and failures to a central log, that the target system records the calling account, and that log retention matches your policy. The security operations team should own log review, with the platform team owning what the hook logs.
When hookscripts are the right tool and when an external orchestrator fits better
A hookscript fits when the action must run on the node that is handling the guest lifecycle event, and an external orchestrator fits when the action must be coordinated across systems and retried until it succeeds. A hookscript is a script attached to a guest, so it runs inside Proxmox VE's own task flow at start, stop or migration. That tight coupling is its strength: the action happens whether or not anyone runs a pipeline, and it cannot be skipped by an operator who starts a VM from the web interface. The cost is that state lives on the node, in the snippet file and in whatever the script writes locally, and a failure surfaces mainly in the node's task log and the guest's task history. Nobody is paged by a hookscript unless you have built that alerting yourself. Confirm where your change process stores snippet files, who may edit them, and whether a change to a shared snippet is reviewed like any other infrastructure code.
An external orchestrator, such as a job driven by Terraform or OpenTofu, Ansible or a CI pipeline calling the Proxmox VE API, keeps its state in a place you already monitor, such as a state backend, a pipeline record or a ticket. Failures land where the on-call team looks, and a failed registration in a CMDB or DNS can be retried without touching the hypervisor. The trade-off is that the action only runs when the pipeline runs, so a VM started by hand may never be registered. Ask the team how each path behaves when the CMDB or DNS service is down: a hookscript that blocks guest start on a failed call can stop production workloads, while one that logs and continues can leave records stale. Decide which behavior is acceptable per action before choosing the mechanism.
In practice many teams use both. Packer and Terraform or OpenTofu create the guest and its baseline, Ansible handles configuration that needs an operating system login, and a narrow hookscript handles the small set of actions that must follow every start or migration on the node. Confirm with your own change owners which of these actions must be reviewed, tested in a non-production cluster and rolled back, and whether a hookscript change needs the same approval as a template change. Plan for the cases where the hookscript and the orchestrator both act on the same record, since the last writer wins unless you define ownership.
Limits to confirm before building on hookscripts
Hookscripts sit on top of Proxmox VE behavior that varies by version, node and recovery path. The cards below list the points to confirm in your own environment, with the documentation or the vendor, before any guest lifecycle logic depends on them.
Phases and arguments per version
Confirm the exact hook phases exposed by your Proxmox VE version, including which phases run on start, stop, migration and restart, and what arguments the script receives in each. Hook interfaces can change between major releases, and a script written against one version may silently receive different inputs on another. Test each phase on a non-production guest and record the arguments you actually see.
Proxmox VE docsFailure behavior in each phase
Find out what happens when a hookscript exits with an error in each phase. Some failures may stop the guest operation, while others may only be logged, and the answer can differ between a pre-start phase and a post-stop phase. Ask whether a failed hook leaves the guest in a half-started or half-migrated state, and design the script to return codes that match the outcome you want.
Hooks during HA recovery and automated migration
Confirm whether hookscripts run when high availability restarts a guest on another node after a failure, and when the scheduler or maintenance mode moves guests automatically. Recovery paths often run under time pressure and with a node that is already unhealthy, so an action such as a DNS update or CMDB write may run late, twice or not at all. Check this in a test cluster that uses the same HA configuration as production.
Behavior across cluster nodes
Confirm where the hookscript must exist and whether it executes on the node where the guest runs, the target node during migration, or both. In a cluster, a script present on one node only will fail on the others, and a script that writes local state will diverge between nodes. Identify which node runs each phase and make external side effects idempotent so a repeated run is harmless.
Distribution and sync of the script
Decide how the script reaches every node and how changes are rolled out and verified. Hookscripts are usually stored in snippet storage, and that storage must be available on each node that can run the guest. Ask how you will detect a drifted copy, who owns the file, and how a rollback works. Ansible, configuration management or a pinned version check are common ways to keep copies identical.
Coverage by the supplier's support tier
Ask the vendor whether support covers custom hookscripts, or only the Proxmox VE software itself. Support tickets for a platform issue may be declined when the cause is a script you wrote, so confirm the ticket scope before you depend on it. Your subscription tier sets the number of tickets and response times, which you should compare with how quickly you need help if a hook blocks guest starts.
Pricing and support tiersQuestions teams ask before hiring help with hookscripts
How much does a Proxmox VE hookscript project cost?
No fixed price applies, because the cost follows from the written scope rather than from the script itself. The main drivers are the number of systems the hook touches (a CMDB, a DNS server, a monitoring tool, a ticketing API), the failure rules you want for each phase, the testing scope across nodes and guest types, and how much change control your organization requires. DeployOpen does not publish a price list, so ask for a quote built from a written scope that lists each integration, each phase (pre-start, post-start, pre-stop, post-stop, pre-migration, post-migration), and the test environment used to prove it. Separate the one-time build from any recurring support.
How long does a hookscript engagement take?
Duration depends mainly on how many external systems the hook must reach, how many phases it covers, and how quickly your team can give access to test accounts and a staging cluster. A single phase writing to one system is a small piece of work, while several phases that update a CMDB, register DNS records and roll back on partial failure take longer to design and verify. Ask the proposal to state the timeline per milestone and to name which of your reviews, approvals or access grants sit on the critical path.
What does the client team need to provide for this work?
You need to provide the system owners and API access for every target the hook will call, a non-production Proxmox VE cluster or a representative test setup, and a named approver for the failure behavior. Your team also supplies the naming rules, DNS zones, CMDB fields and service account policy the scripts must follow. Without these inputs, the scope cannot be fixed, and the testing will not reflect production. List each dependency in the scope so that delays on your side are visible early.
Can our own engineers build hookscripts without outside help?
Yes, a team with Linux shell or Perl experience and familiarity with the Proxmox VE hookscript mechanism can build simple scripts in-house. The harder parts are usually the failure handling, idempotent registration and removal, credential storage, and testing migrations between nodes, which are easy to underestimate. Consider whether your team can own the scripts after go-live, review changes, and rerun tests after each Proxmox VE upgrade. An outside partner can help with any of these, and a written scope makes the handover explicit.
What breaks when a node fails during a hookscript run?
A hook that has started but not finished can leave a guest registered in a CMDB or DNS while the guest is running elsewhere, or can leave a stale record after a failed stop. High availability adds a further case: the cluster recovers guests on another node, which runs the start phase again, so the script must tolerate repeated execution. Design the scripts so each action can be retried, record what was changed, and define whether a failed hook blocks the guest or only logs a warning. Test node power loss during each phase, not only clean shutdowns.
How are hookscripts maintained after go-live?
Maintenance covers version control of the scripts, review of changes, monitoring of hook failures, updates when target APIs change, and retesting after each Proxmox VE upgrade. Ask who owns each part and where the scripts are stored, and confirm whether credentials are rotated through your secrets process. Support can be handled by your team, by a retainer, or by a mix, and the written scope should name which of these applies and how changes are approved.
How do we protect credentials used by hookscripts?
Hookscripts often call CMDB, DNS or ticketing APIs, so they need credentials that are scoped to the minimum actions required and stored outside the script body. Use a dedicated service account or API token per integration, restrict file permissions on the snippet storage, and confirm how the token is rotated. Review the Proxmox VE user management documentation for the authentication and permission model that applies to your cluster, and have the scope state who approves access to the snippet directory.
Does a hookscript project support our compliance evidence needs?
A hookscript project can produce the evidence your auditors ask for, such as a change record for each script, test results for failure cases, and logs showing when registrations were made. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications, and independent auditors make that determination. Ask the scope to list the evidence artifacts, retention location and review steps before work starts.
How DeployOpen scopes, builds and supports hookscript automation
DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure, including Proxmox VE. For hookscripts, we start from the lifecycle events your organization needs to act on, then build and test the scripts in your environment before they touch production guests.
How we scope
- We agree the lifecycle phases, guest types and cluster nodes in scope before any work starts.
- Scope covers the systems each hook calls, such as the CMDB, DNS or ticketing API, and their credentials.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work begins.
How we build
- We build hookscripts on a non-production Proxmox VE cluster and set snippet storage paths and permissions for each node.
- Each phase is tested with failure cases, including unreachable APIs, partial failures and migrations interrupted midway.
- Scripts are version controlled, with logging that shows which action ran, on which node, and with what result.
How we hand over
- You receive the scripts, configuration, deployment steps and a record of test results for each lifecycle phase.
- Documentation explains failure handling, retry behavior and which hooks must never block a guest start.
- We walk your platform and security teams through the code and the operational runbook before handover.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, including checks after Proxmox VE upgrades.
- We confirm hookscript behavior against each Proxmox VE release before you move that release into production.
- Changes to downstream systems such as the CMDB or DNS are retested so automation does not quietly fail.

