Created
April 26, 2015 03:19
-
-
Save heathdutton/cc29284de3934706acd1 to your computer and use it in GitHub Desktop.
Start an Acquia drush command, and wait for it to complete before continuing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Runs an acquia task, and waits for the task to complete before continuing. | |
# This is a helper script, to be used in others as needed. | |
if [[ $1 = "" ]] || [[ $2 = "" ]] | |
then | |
echo "Runs an acquia drush command, waiting for the results before continuing." | |
echo "Can be used as a replacement for drush." | |
echo | |
echo " Usage: $0 <site-alias> <ac-drush-command>" | |
echo " Example: $0 @site.prod ac-database-instance-backup site" | |
exit 1 | |
fi | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
ac_command="$2" | |
drush_command="drush "$@"" | |
if [[ $ac_command = "ac-code-deploy" ]] || | |
[[ $ac_command = "ac-code-path-deploy" ]] || | |
[[ $ac_command = "ac-database-add" ]] || | |
[[ $ac_command = "ac-database-copy" ]] || | |
[[ $ac_command = "ac-database-delete" ]] || | |
[[ $ac_command = "ac-database-instance-backup" ]] || | |
[[ $ac_command = "ac-database-instance-backup-delete" ]] || | |
[[ $ac_command = "ac-database-instance-backup-restore" ]] || | |
[[ $ac_command = "ac-domain-add" ]] || | |
[[ $ac_command = "ac-domain-delete" ]] || | |
[[ $ac_command = "ac-domain-move" ]] || | |
[[ $ac_command = "ac-domain-purge" ]] || | |
[[ $ac_command = "ac-environment-install" ]] || | |
[[ $ac_command = "ac-files-copy" ]] | |
then | |
echo "${0//.sh/}:" | |
echo " Command: $drush_command" | |
json="$($drush_command --format=json)" | |
id="$(echo $json | sed "s/},/\n/g" | sed 's/.*"id":"\([^"]*\)".*/\1/')" | |
echo " Task: $id" | |
oldlogs="" | |
while [[ $state != "done" && $state != "error" ]] | |
do | |
# Checking consumes resources, so wait for 3 seconds between checks. | |
sleep 3 | |
json="$(drush $1 ac-task-info $id --format=json)" | |
state="$(echo $json | sed "s/},/\n/g" | sed 's/.*"state":"\([^"]*\)".*/\1/')" | |
newlogs="$(echo $json | sed "s/},/\n/g" | sed 's/.*"logs":"\([^"]*\)".*/\1/')" | |
if [[ $newlogs != $oldlogs ]] | |
then | |
logdiff=${newlogs//"$oldlogs"/} | |
logdiff=${logdiff//"\n"/} | |
if [[ $logdiff != "" ]] | |
then | |
echo " $logdiff" | |
fi | |
fi | |
oldlogs="$newlogs" | |
done | |
if [[ $state = "error" ]] | |
then | |
echo -e " State: ${RED}$state${NC}" | |
exit 1 | |
else | |
echo -e " State: ${GREEN}$state${NC}" | |
fi | |
else | |
# Fall back to standard drush command if this is not a known asyncronous command | |
drush "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment