Hooks¶
Hooks are scripts that automatically trigger actions based on an event performed in the life cycle of an instance. A hook can be any executable file that is placed in the hooks
directory of an addon or an application folder.
The hook name must be one of the following:
Name |
Description |
---|---|
pre-start |
Executed before Android is started. If the hook fails to execute, the instance fails to start and has an error status. |
post-start |
Executed after Android is started. If the hook fails to execute, the instance stops with an error. |
post-stop |
Executed after Android is stopped. If the instance fails to start, this hook will not be invoked. If the hook fails to execute, the instance stops with an error. |
install (deprecated) |
DEPRECATED: Use |
prepare (deprecated) |
DEPRECATED: Use |
restore (deprecated) |
DEPRECATED: Use |
backup (deprecated) |
DEPRECATED: Use |
A failed hook will cause the instance to stop immediately and end up in an error state. In such cases, see How to view the instance logs to further investigate the causes of failure.
The following figure shows when the different hooks are executed in the life cycle of a base or a regular instance.
Environment variables¶
When hooks are invoked, several environment variables are set to provide context to the addon.
The following variables are available:
Name |
Description |
Possible values |
---|---|---|
|
Directory of the addon whose hook is currently running. |
|
|
Path to the Anbox application directory. |
|
|
Path to the Anbox directory. |
|
|
Path to the Android RootFS. |
|
|
Boot package of the APK. |
|
|
Type of container being run. This variable is now deprecated. Use |
|
|
Type of instance being run |
|
|
|
|
Hook timeouts¶
By default, all hooks are subject to a 5 minute timeout to avoid blocking an instance for too long. The timeout can be configured through the hooks.timeout
key in the addon or application manifest. For example:
...
hooks:
timeout: 15m
...
A hook that runs into a timeout exits with an error. Timeout values longer than 15 minutes are considered invalid.