Adding a deploy hook


Deploy hooks are scripts that allow you to automate actions at various points during the deployment process for your applications. This allows you to customise your deployments by, for example, installing software packages or upgrading components.

We will be walking through a simple example in this tutorial. For more detailed examples please read the in-depth How-to Guide. For a full list of every available option please read our reference guide.

What you’ll need

Before you start, please check you have the following:

Creating a deploy hook

Deploy hooks can be added to an application via the Dashboard. Like most other configuration templates in Maestro, Deploy hooks are YAML-formatted.

A deploy hook needs, at a minimum:


If you choose a specific server type as your target (i.e. anything other than any) then your run_on field will default to single_server unless you explicitly set it to all_servers. If you set your server_type to any, then this field is ignored.

So, to write a deploy hook you must:

  1. Choose your hook point - e.g. first_thing
  2. Choose your hook type - e.g. command
  3. Set a target server-type for the hook - e.g. mysql
  4. If your target is not any then set the run_on to either single_server or all_servers.
  5. Configure the hook fields you require

While this is the bare minimum required to write a functional deploy hook, there are extensive options available for customization. Please read our reference guide to understand all the possibilities.

Writing the YAML

The simplest kind of hook is the command. This simply executes a command in the operating system as part of the deployment process.

We’re going to add the hook below to our demo application:

    first_thing: # Hook point
      - command: apt-get install nmap -y # Hook type
        target: any # Hook fields
        execute: true

This hook will install the nmap package on our server during the deployment process. We’ve added the execute hook field because we want the command to be executed during deployment. If you don’t add this field, the code you’re calling won’t be executed.


When automating the installation of packages, remember to use the -y flag to answer yes to all prompts.

Adding the hook to your app

Hooks can be added to an application in one of two ways:

We’re going to use the first method in our tutorial because it’s quicker and simpler.

To add the hook:

  1. Open the Application Overview from your Dashboard
  2. Click on Configuration files in the Application panel on the right of the screen
  3. Click on the Deploy Hooks tab at the top of the Configure Services
  4. Copy and paste the example code above into the text area
  5. Click Preview and then check there are no errors in the parsed template file
  6. Add a commit message and click Commit to server

Deploying and testing

Now that our hook is in place, we need to re-deploy our application to see it in action.

  1. Navigate back to Application Overview
  2. Click the Build / Deploy button
  3. Watch the deploy log and you will see the “first _thing” deploy hook being called as part of the process

(As always, we recommend testing your hooks in a non-production environment before using on your live application.)

The best way to check whether your change has been applied to your server is to access it directly using SSH. Cloud 66 Toolbelt is the quickest way to do this.

Once you are connected to your server, type nmap into the terminal. If your deploy hook was set up correctly, you will see the usage / help text for the nmap utility. If not, Ubuntu will complain that nmap is not installed.

What’s next?