Boot & shutdown hooks
Hooks let you run your own scripts at defined points in the device lifecycle — for example to prepare hardware, mount a special device, or clean up on shutdown. They are the supported way to extend device behavior without modifying the read-only system image.
Available hooks
You can provide a script for each of these points:
| Hook | Runs |
|---|---|
| On boot | Early in startup, before the device agent starts. |
| After the agent starts | Once the device agent is up. |
| On shutdown | When the device is shutting down or rebooting. |
How to provide a hook
Place an executable script in the hooks location on the device’s configuration storage. Because it lives on configuration storage, the script persists across reboots and OS upgrades and is run automatically at the corresponding point. See the persistent paths reference for the exact location.
Guidelines
- Keep hooks fast and resilient. A slow or failing boot hook delays startup; make hooks idempotent and have them exit cleanly.
- Do not rely on modifying the system image. Use hooks to act on configuration and data, not to patch the OS — image changes do not persist.
- Log from your hook so you can see what it did via logging.
- Test on one device first before distributing a hook to a fleet.