travis_setup.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. export DEBIAN_FRONTEND=noninteractive
  2. # Turn on command tracing
  3. set -x
  4. # Setup Apt For MongoDB
  5. # Due to TechEmpower/FrameworkBenchmarks#989 and travis-ci/travis-ci#2655,
  6. # we put this into a loop
  7. until timeout 15s sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10; do echo 'Waiting for apt-key' ; done
  8. echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
  9. # Setup apt for Apache Cassandra
  10. until timeout 15s sudo apt-key adv --keyserver pgp.mit.edu --recv 4BD736A82B5C1B00; do echo 'Waiting for apt-key' ; done
  11. sudo apt-add-repository 'deb http://www.apache.org/dist/cassandra/debian 20x main'
  12. # Run installation
  13. # DO NOT COPY --force-yes TO ANY NON-TRAVIS-CI SCRIPTS! Seriously, it can cause some
  14. # major damage and should only be used inside a VM or Linux Container
  15. sudo apt-get -q update
  16. sudo apt-get -q -y --force-yes install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
  17. mongodb-org \
  18. cassandra \
  19. openssh-server \
  20. mysql-server
  21. # Run as travis user (who already has passwordless sudo)
  22. ssh-keygen -f /home/travis/.ssh/id_rsa -N '' -t rsa
  23. cat /home/travis/.ssh/id_rsa.pub > /home/travis/.ssh/authorized_keys
  24. chmod 600 /home/travis/.ssh/authorized_keys
  25. # Set up the benchmark.cfg for travis user
  26. # NOTE: Please don't just copy the example config - it causes unexpected
  27. # issues when those example variables change
  28. echo "[Defaults]" > benchmark.cfg
  29. echo "client_identity_file=/home/travis/.ssh/id_rsa" >> benchmark.cfg
  30. echo "database_identity_file=/home/travis/.ssh/id_rsa" >> benchmark.cfg
  31. echo "client_host=127.0.0.1" >> benchmark.cfg
  32. echo "database_host=127.0.0.1" >> benchmark.cfg
  33. echo "server_host=127.0.0.1" >> benchmark.cfg
  34. echo "client_user=travis" >> benchmark.cfg
  35. echo "database_user=travis" >> benchmark.cfg
  36. echo "runner_user=testrunner" >> benchmark.cfg
  37. # Create the new testrunner user
  38. sudo useradd testrunner
  39. # Give him a home dir
  40. sudo mkdir /home/testrunner
  41. # Make testrunner the owner of his home dir
  42. sudo chown testrunner:testrunner /home/testrunner
  43. # Add the testrunner user to every group that the travis user is in
  44. sudo sed -i 's|:travis|:travis,testrunner,benchmarkdbuser|g' /etc/group
  45. # Maybe unneeded - add the travis user to the testrunner group
  46. sudo sed -i 's|testrunner:x:\(.*\):|testrunner:x:\1:travis|g' /etc/group
  47. # Need to add testrunner to the sudoers group AND default him to a sudoers
  48. # because the travis user isn't in the sudo group - he's a sudoer.
  49. echo "testrunner ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
  50. # Set the default shell for testrunner to /bin/bash
  51. sudo sed -i 's|/home/testrunner:/bin/sh|/home/testrunner:/bin/bash|g' /etc/passwd
  52. mkdir installs
  53. sudo chown testrunner:testrunner installs
  54. # =============Setup Databases===========================
  55. # NOTE: Do not run `--install database` in travis-ci!
  56. # It changes DB configuration files and will break everything
  57. # =======================================================
  58. # Setup MySQL
  59. echo "Populating MySQL database"
  60. #sudo mysqladmin -u root password secret
  61. #sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  62. #sudo mv config/my.cnf /etc/mysql/my.cnf
  63. sudo sed -i 's|#max_connections = 100|max_connections = 500|g' /etc/mysql/my.cnf
  64. sudo restart mysql
  65. #mysql -uroot -psecret < config/create.sql
  66. # Setup Postgres
  67. echo "Removing Postgres 9.1 from Travis-CI"
  68. sudo apt-get remove -qy postgresql postgresql-9.1 postgresql-client-9.1
  69. sudo apt-get install -qy postgresql-9.3 postgresql-client-9.3
  70. echo "Populating Postgres database"
  71. psql --version
  72. sudo useradd benchmarkdbuser -p benchmarkdbpass
  73. sudo -u postgres psql template1 < config/create-postgres-database.sql
  74. sudo -u benchmarkdbuser psql hello_world < config/create-postgres.sql
  75. sudo sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /etc/postgresql/9.3/main/postgresql.conf
  76. sudo sed -i 's|max_connections = 255|max_connections = 500|g' /etc/postgresql/9.3/main/postgresql.conf
  77. sudo service postgresql stop
  78. sudo service postgresql start 9.3
  79. # Setup Apache Cassandra
  80. echo "Populating Apache Cassandra database"
  81. for i in {1..15}; do
  82. nc -z localhost 9160 && break || sleep 1;
  83. echo "Waiting for Cassandra ($i/15}"
  84. done
  85. nc -z localhost 9160
  86. if [ $? -eq 0 ]; then
  87. cat config/cassandra/cleanup-keyspace.cql | sudo cqlsh
  88. python config/cassandra/db-data-gen.py > config/cassandra/tfb-data.cql
  89. sudo cqlsh -f config/cassandra/create-keyspace.cql
  90. sudo cqlsh -f config/cassandra/tfb-data.cql
  91. else
  92. >&2 echo "Cassandra did not start, skipping"
  93. fi
  94. # Setup Elasticsearch
  95. curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.5.0.deb
  96. sudo dpkg -i --force-confnew elasticsearch-1.5.0.deb
  97. sudo update-rc.d elasticsearch defaults 95 10
  98. sudo service elasticsearch restart
  99. echo "Populating Elasticsearch database"
  100. for i in {1..15}; do
  101. nc -z localhost 9200 && break || sleep 1;
  102. echo "Waiting for Elasticsearch ($i/15}"
  103. done
  104. nc -z localhost 9200
  105. if [ $? -eq 0 ]; then
  106. curl localhost:9200
  107. sh config/elasticsearch/es-create-index.sh
  108. python config/elasticsearch/es-db-data-gen.py > config/elasticsearch/tfb-data.json
  109. curl -sS -D - -o /dev/null -XPOST localhost:9200/tfb/world/_bulk --data-binary @config/elasticsearch/tfb-data.json
  110. echo "Elasticsearch DB populated"
  111. else
  112. >&2 echo "Elasticsearch did not start, skipping"
  113. fi
  114. # Setup MongoDB
  115. echo "Populating MongoDB database"
  116. for i in {1..15}; do
  117. nc -z localhost 27017 && break || sleep 1;
  118. echo "Waiting for MongoDB ($i/15}"
  119. done
  120. nc -z localhost 27017
  121. if [ $? -eq 0 ]; then
  122. mongo < config/create.js
  123. mongod --version
  124. else
  125. >&2 echo "MongoDB did not start, skipping"
  126. fi
  127. # =============Modify Configurations===========================
  128. # It can be useful to enable debug features for verification
  129. # inside Travis-CI
  130. # =======================================================
  131. sed -i 's|display_errors\] = off|display_errors\] = on|' config/php-fpm.conf
  132. #exit $?