Created
August 2, 2016 06:53
-
-
Save waleedsamy/04159808c4992f2a85dacb42cd08507c to your computer and use it in GitHub Desktop.
parallel deploy in cluster after splitting it's machines to make sure if something go wrong, there will be a running instances in some servers
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
#!/usr/bin/env bash | |
# should have your public key added in every machine server | |
user=deploybot | |
servers=(127.18.34.122 127.18.34.123 127.18.34.124 127.18.34.125 127.18.34.126 127.18.34.127 127.18.34.128 127.18.34.129 127.18.34.130) | |
count=${#servers[@]} | |
deploy(){ | |
cluster=("$@") | |
echo deploying to cluster ${cluster[@]} | |
# run deploy in parallel for every machine in the cluster | |
for server in "${cluster[@]}"; do | |
(ssh $user@${server} "DEPLOY_COMMAND") & | |
done | |
wait | |
} | |
#split to two cluster | |
half=$((count / 2)) | |
a_cluster=("${servers[@]:0:$half}") | |
b_cluster=("${servers[@]:$half}") | |
# deploy to first cluster then second one | |
# if deployment failed in first cluster, second one will not be updated, to make sure nothing is broken | |
deploy "${a_cluster[@]}" && deploy "${b_cluster[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment