diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/ruflin/elastica/ansible/provision.sh | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/ruflin/elastica/ansible/provision.sh')
-rwxr-xr-x | vendor/ruflin/elastica/ansible/provision.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/ansible/provision.sh b/vendor/ruflin/elastica/ansible/provision.sh new file mode 100755 index 00000000..6ea8e575 --- /dev/null +++ b/vendor/ruflin/elastica/ansible/provision.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -o xtrace + +install_ansible() { + sudo apt-get update + sudo apt-get install python python-pip python-dev -y + sudo pip install ansible==1.8.2 + sudo mkdir -p /etc/ansible/ + echo "localhost" | sudo tee /etc/ansible/hosts +} + +run_playbook() { + # Write to stdout directly + export PYTHONUNBUFFERED=1 + + # No cows >_< + export ANSIBLE_NOCOWS=1 + + # Root of git repo + if [ -z "$ES_PROJECT_ROOT" ]; then + export ES_PROJECT_ROOT="$(dirname $(dirname $(readlink -f $0)))" + fi + + if [ ! -x $(which ansible-playbook) ]; then + echo "Ansible is not installed" + return 1 + fi + + ansible-playbook $ES_PROJECT_ROOT/ansible/es-playbook.yml -v | tee /tmp/ansible-playbook-progress + + if grep -q "FATAL\|ERROR" /tmp/ansible-playbook-progress; then + return 1 + fi +} + +check_cluster() { + curl -m 5 -s -o /dev/null "http://localhost:9200" && + curl -m 5 -s -o /dev/null "http://localhost:9201" + return $? +} + +travis_retry() { + # We don't use builtin Travis CI function, because this script is also used for vagrant provision. + # But main idea of restarts is so simple, so lets override it without name change. + + $@ && return 0 + + echo "The command $@ failed. Retrying, 2 of 3" + sleep 60s && $@ && return 0 + + echo "The command $@ failed. Retrying, 3 of 3" + sleep 60s && $@ && return 0 + + echo "The command $@ failed." + return 1 +} + +travis_retry install_ansible || exit 1 + +travis_retry run_playbook || exit 1 + +travis_retry check_cluster || exit 1 |