The Deploy system supports hooks that are started before or after deployment.
These hooks are executable files of any kind (e.g. shell scripts, Linux executable binaries).
Hooks are not executed when a deployment process is triggered by automatic processes such as scaling out an instance of a autoscaling group because of high load. They are only executed through calling r3 deploy.
Table of contents
General usage instructions
(For your reference: general usage instructions for the cloud managment tool suite r3)
The hook system is disabled by default and can be activated and controlled via options. You can find the details below.
Step-by-step guide
Show help context
How to use hooks
The --pre-hook
option enables the hooks to be started before deploying and sets the directory with pre-hooks. If no explicit path is specified, the path pre-hook.d
is used in the project directory (e.g. git-root).
The --post-hook
option enables the hooks to be started after deployment and sets the directory with post hooks. If no explicit path is specified, the path post-hook.d
is used in the project directory (eg git-root).
Hooks are valid only under the following conditions:
- The executable flag of the file of the hook is set. The flag must already be set in your deployment before r3 deploy copies it to us.
- If you are using Windows and git, use "
git add --chmod=+x
00_somehook.sh" to set the flag.
- If you are using Windows and git, use "
- The filename starts with a two-digit number (00-99) followed by a _ (underscore), e.g.
00_firsthook
,10_otherhook.sh
The hooks will run in the context of the project user on the natgw/jump server/bastion host. You can use any command in the hook that you can also use manually.
The hooks are called with the following options:
-p project
: project name-r role
: server group name (e.g.web
)-e environment
: environment name (e.g.test
)
Example Hook:
#!/bin/bash source /usr/local/lib/helper.sh function usage() { echo "${SCRIPT} [-r role] [-p project] [-e environment] [-q|-d] [-h]" echo " -h : print this help" echo " -r role : server role" echo " -p project : project name" echo " -e environment : environment name" exit 1 } # iterate options while getopts ':hr:p:e:' opt; do case "${opt}" in "r") role="${OPTARG}" ;; "p") project="${OPTARG}" ;; "e") environment="${OPTARG}" ;; "h") usage ;; ":") log error "Missing argument for option ${OPTARG}" usage ;; *) log error "Unknown option ${opt}" usage ;; esac done # print given project, environment and role echo "${project}-${environment}-${role}" # iterate all servers with given role in current project and run a command for target in $(get-instances-by-role "${role}" --output text | awk -F ' ' '{print$2}' | grep -v 'ip'); do # connect to server and run cache.php if ssh "${target}" php /var/www/cache.php; then # if command run successfully on one server skip all other break fi done # do some more stuff