Last active
January 31, 2018 16:48
-
-
Save Jinkxed/ae0f4acbb5b7283a2dc0b25a3277cf50 to your computer and use it in GitHub Desktop.
check-codedeploy.sh
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 | |
# | |
# check-codedeploy check-codedeploy shipper | |
# | |
# chkconfig: 2345 98 02 | |
# description: Starts and stops a single check-codedeploy instance on this system | |
# | |
### BEGIN INIT INFO | |
# Provides: check-codedeploy | |
# Required-Start: $local_fs $network $syslog | |
# Required-Stop: $local_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
### END INIT INFO | |
# This gives us our custom tags that are applied to each instance | |
# ENVIRONMENT, PRODUCT, ROLE, TEAM | |
# We will use these variables to determine it's application and deployment group it needs to check | |
. /usr/bin/get-meta | |
. /etc/bashrc | |
function ensureTagsSet() { | |
echo "----------------------------------------------------------------------------------" | |
echo "" | |
while [[ $PRODUCT == 'template' ]]; do | |
echo "Tags not set yet. Waiting 5 seconds and checking again." | |
sleep 5 | |
. /usr/bin/get-meta | |
. /etc/bashrc | |
done | |
} | |
function setDeploymentGroup() { | |
echo "" | |
echo "Getting Deployment Group" | |
case $ENVIRONMENT in | |
production) | |
if [[ $ROLE == 'cron' ]] || [[ $ROLE == 'worker' ]]; then | |
DEPLOYMENTGROUP=production_workers | |
else | |
DEPLOYMENTGROUP=production | |
fi;; | |
uat) | |
DEPLOYMENTGROUP=uat;; | |
staging) | |
DEPLOYMENTGROUP=${PRODUCT}_${TEAM};; | |
*) | |
DEPLOYMENTGROUP=${PRODUCT}_${TEAM};; | |
esac | |
echo "- Deployment Group set to: $DEPLOYMENTGROUP" | |
} | |
function update-instance() { | |
ensureTagsSet | |
setDeploymentGroup | |
echo "" | |
echo "- Checking if code has been deployed to this instance" | |
CREATE_DEPLOYMENT=$(aws deploy create-deployment --application-name $PRODUCT --deployment-group $DEPLOYMENTGROUP --update-outdated-instances-only) | |
DEPLOYMENT_RESULT=$? | |
echo "" | |
echo "- Deploy Command: aws deploy create-deployment --application-name $PRODUCT --deployment-group $DEPLOYMENTGROUP --update-outdated-instances-only" | |
echo "- Deploy Code: $DEPLOYMENT_RESULT" | |
echo "----------------------------------------------------------------------------------" | |
echo "" | |
} | |
update-instance 2>&1 | tee /var/log/check-codedeploy.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment