provision.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. set -o xtrace
  3. install_ansible() {
  4. sudo apt-get update
  5. sudo apt-get install python python-pip python-dev -y
  6. sudo pip install ansible==1.8.2
  7. sudo mkdir -p /etc/ansible/
  8. echo "localhost" | sudo tee /etc/ansible/hosts
  9. }
  10. run_playbook() {
  11. # Write to stdout directly
  12. export PYTHONUNBUFFERED=1
  13. # No cows >_<
  14. export ANSIBLE_NOCOWS=1
  15. # Root of git repo
  16. if [ -z "$ES_PROJECT_ROOT" ]; then
  17. export ES_PROJECT_ROOT="$(dirname $(dirname $(readlink -f $0)))"
  18. fi
  19. if [ ! -x $(which ansible-playbook) ]; then
  20. echo "Ansible is not installed"
  21. return 1
  22. fi
  23. ansible-playbook $ES_PROJECT_ROOT/ansible/es-playbook.yml -v | tee /tmp/ansible-playbook-progress
  24. if grep -q "FATAL\|ERROR" /tmp/ansible-playbook-progress; then
  25. return 1
  26. fi
  27. }
  28. check_cluster() {
  29. curl -m 5 -s -o /dev/null "http://localhost:9200" &&
  30. curl -m 5 -s -o /dev/null "http://localhost:9201"
  31. return $?
  32. }
  33. travis_retry() {
  34. # We don't use builtin Travis CI function, because this script is also used for vagrant provision.
  35. # But main idea of restarts is so simple, so lets override it without name change.
  36. $@ && return 0
  37. echo "The command $@ failed. Retrying, 2 of 3"
  38. sleep 60s && $@ && return 0
  39. echo "The command $@ failed. Retrying, 3 of 3"
  40. sleep 60s && $@ && return 0
  41. echo "The command $@ failed."
  42. return 1
  43. }
  44. travis_retry install_ansible || exit 1
  45. travis_retry run_playbook || exit 1
  46. travis_retry check_cluster || exit 1