Events allow you to fine-tune your Lando experience by running commands on specific services before or after parts of the Lando runtime. This is super helpful if you want to clear caches after a database import, or compile sass after an app is started.

Specifically, you need to hook into an event where the service you are running the command against exists and is running.

When should I use events?

Unlike build steps events will run every time so it is advisable to use them for automating common steps like compiling sass before or after your app starts and not installing lower level dependencies like node modules or php extensions.


Consider the following example to get an understanding on how the events framework works.

# Name of the events example
name: events

# Start with the lemp recipe and some recipe config
recipe: lemp
  via: nginx
  php: 7.1
  webroot: www

# Add in some custom event scripting

  # Run a command before the app starts
    - echo "PARTY IN THE USA!"

  # Run some commands after `lando db-import`

    # Run `drush version` on the appserver service
    - appserver: drush version

    # Print out "test this command" on a service determined by lando
    # If no service is specified in the format {SERVICENAME: CMD} lando will
    # attempt to determine the best service to run the command on.
    # If the event is a tooling command (as is the case here) lando will run
    # this command on that service. Otherwise lando will use `appserver`
    - echo "test this command"

  # Run some commands after `lando test`
    - echo "Tests complete!"

  # Run some commands after `lando start`
    - echo "App restarted!"
    - database: env

# Provide a trivial command to help test the event framework
    description: Test command for event framework
    cmd: true
    service: appserver

You can check out the full code for this example over here.

Discovering Events

You can also explore various events by running:

# Discover hookable events for the `lando start` command
lando start -- -vvv | grep "Emitting"

# Discover hookable events for the `lando test` command
# NOTE: This assumed you've defined a `test` command in tooling
lando test -- -vvv | grep "Emitting"

results matching ""

    No results matching ""