Lifecycle Hooks Usage
You can use hooks to run scripts at specific steps of the Lono lifecycle.
|build||When Lono builds the blueprint.|
|down||When Lono deletes the stack.|
|up||When Lono deploys the stack.|
To help you get started quickly, you can generate starter hook code. Check out the examples in the Hooks Generator Docs.
before("build", execute: "echo hi", ) after("build", execute: "echo bye" )
exit on fail
By default, if the hook commands fail, then lono will exit with the original hook error code. You can change this behavior with the
before("build", execute: "/command/will/fail/but/will/continue", exit_on_fail: false, )
In this case, regardless of the hook command succeeding or failing, Lono will continue right along.
The command name corresponds to the
|label||A human-friendly label so you can see what hooks is being run.|
|execute||The script or command to run. IE: path/to/some/script.sh|
|exit_on_fail||Whether or not to continue process if the script returns an failed exit code.|
Instead of using a script for the hook
execute option, you can also use a Ruby object. This provides some more control over the current process. See: Ruby Hooks
If you need to hook into the Lono boot process super-early on, check out Boot Hook.
The context in which the hook runs is worth highlighting. When the
execute option is a String, Lono runs the script in a new child process. This the script is an independent process, and whatever is done to its environment is segregated.
execute option a Ruby object, then Lono runs the hook within the same process. It means the hook can affect the same environment. IE: Setting environment variables.