Information for: DEVELOPERS   PARTNERS

post-staging-update hook in Acquia Cloud Site Factory

After you stage your production websites to a non-production environment, you must run commands on your newly staged websites to synchronize them with your source environment’s data structure.

You can synchronize data with the post-staging-update hook for your environment. If you don’t create a post-staging-update hook script, Acquia Cloud Site Factory will instead execute the default drush updatedb command.

Note

The post-staging-update hook executes only if the non-production and production environments aren’t running the same code.

Using the post-staging-update hook

Like several of the other hooks in use by Acquia Cloud Site Factory, you will create a script file following best practices for hook scripts. Place the script in a particular directory. Scripts in that directory are run in alphabetical order after the data copying process for each website being staged.

To use the post-staging-update hook, complete the following steps:

  1. Create a script file including the commands to run after a staging deployment. You can create more than one script file for use with this hook, but the scripts will run in alphabetical order.

  2. Create a directory called factory-hooks in the root of your code repository, if it doesn’t already exist.

    Note

    The factory-hooks and docroot directories are separate directories at the same level in your code repository.

  3. Create a post-staging-update directory in the factory-hooks directory, if it doesn’t already exist.

  4. In the /factory-hooks/post-staging-update directory, add the script file or files you created for this procedure.

  5. Examine the files you created to ensure they have the executable flag. Failing to set the executable flag for scripts can prevent Acquia Cloud Site Factory from executing the files.

After executing a staging deployment, review the newly staged website, as well as any logging output created by your hook script, to check if your hook script executed successfully.

Providing hook arguments

The hook receives alphanumeric arguments, separated by spaces, in the following order:

  1. Sitegroup
  2. Environment
  3. Database role
  4. Domain

Troubleshooting database update hooks

If a script in the post-staging-update directory ends with an error (a non-zero exit code), no additional scripts will run in the directory, and the task logs will display error messages in SynchronizeSingleSite lines. For information about accessing and reading task logs, see Viewing tasks.

Example scripts

Change the following script to meet your needs:

#!/usr/bin/env bash
SITEGROUP="$1"
ENVIRONMENT="$2"
DB_ROLE="$3"
DOMAIN="$4"

echo "domain: $DOMAIN"
echo "sitegroup: $SITEGROUP"
echo "env: $ENVIRONMENT"
echo "db role: $DB_ROLE"

\drush8 -r /var/www/html/$SITEGROUP.$ENVIRONMENT/docroot -l $DOMAIN ev 'echo "Hello world";'