Acquia Cloud Hooks provide a convenient way to script common Drupal tasks like updating databases or clearing cache for your sites.
Hooks can be located in the common directory or they can be located in an environment specific directory such as dev, test or prod. The common directory will run all of the scripts that it contains against all of your environments. This is great for reducing the number of redundant scripts in your hooks directory, but occasionally a script will run on one environment and fail on another.
This often occurs when hooks are run on the RA environment as it may not match the configuration of your other environments. This can result in security updates being delayed due to a failed hook causing tasks to fail.
To prevent this from happening there are two approaches:
The first is to move hooks out of the common directory and into the appropriate subdirectory in each of the environment specific directories like dev, test or prod. To reduce duplication of work, you can symlink the script from one directory into the other environment directories that can and should run it. The following command would symlink a script in the dev/post-db-copy directory to the test/post-db-copy directory:
ln -s hooks/dev/post-db-copy/drush-cache-clear.sh hooks/test/post-db-copy/drush-cache-clear.sh
The second method is to prevent scripts in the common directory from running on the RA environment. This is done by wrapping the functional portion of your script in an if statement.
The wrapper would encompass everything after your list of variables:
if [ "$target_env" != "ra" ]; then
/*
*Place hook code here
*/
fi
For example, using the drush-cache-clear.sh script:
#!/bin/sh
#
# Cloud Hook: drush-cache-clear
#
# Run drush cache-clear all in the target environment. This script works as
# any Cloud hook.
# Map the script inputs to convenient names.
site=$1
target_env=$2
drush_alias=$site'.'$target_env
# Execute a standard drush command.
if [ "$target_env" != "ra" ]; then
drush @$drush_alias cc all
fi
If this script is placed in common/post-db-copy/, it will run for all environments except for RA and will do so whenever a database has been copied to the environment.