bootstrap.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env bash
  2. #
  3. # Prepares a virtual machine for running TFB
  4. #
  5. # Intentionally uses ~, $HOME, and $USER so that the
  6. # same script can work for VirtualBox (username vagrant)
  7. # and Amazon (username ubuntu)
  8. # Add everything passed in the first argument to our
  9. # local environment. This is a hack to let us use
  10. # environment variables defined on the host inside the
  11. # guest machine
  12. while read -r line; do
  13. export $line;
  14. done <<< "$1"
  15. # Are we installing the server machine, the client machine,
  16. # the database machine, or all machines?
  17. # Valid values:
  18. # - all (we are setting up a development environment)
  19. # - database (we are setting up the database machine)
  20. # - client (we are setting up the client machine for load generation)
  21. # - server (we are setting up the machine that will host frameworks)
  22. ROLE=${2:-all}
  23. # Set a number of variables by either pulling them from
  24. # the existing environment or using the default values
  25. # I'm renaming them to indicate that (in this script only)
  26. # the values are provisioner agnostic
  27. SERVER_IP=${TFB_AWS_APP_IP:-172.16.0.16}
  28. CLIENT_IP=${TFB_AWS_LOAD_IP:-172.16.0.17}
  29. DATABA_IP=${TFB_AWS_DB_IP:-172.16.0.18}
  30. if [ "$ROLE" == "all" ]; then
  31. SERVER_IP=127.0.0.1
  32. CLIENT_IP=127.0.0.1
  33. DATABA_IP=127.0.0.1
  34. fi
  35. GH_REPO=${TFB_AWS_REPO_SLUG:-TechEmpower/FrameworkBenchmarks}
  36. GH_BRANCH=${TFB_AWS_REPO_BRANCH:-master}
  37. # A shell provisioner is called multiple times
  38. if [ ! -e "~/.firstboot" ]; then
  39. # Setup some nice TFB defaults
  40. if [ "$ROLE" == "all" ]; then
  41. echo "export TFB_CLIENT_IDENTITY_FILE=$HOME/.ssh/id_rsa" >> ~/.bash_profile
  42. echo "export TFB_DATABASE_IDENTITY_FILE=$HOME/.ssh/id_rsa" >> ~/.bash_profile
  43. else
  44. echo "export TFB_CLIENT_IDENTITY_FILE=$HOME/.ssh/client" >> ~/.bash_profile
  45. echo "export TFB_DATABASE_IDENTITY_FILE=$HOME/.ssh/database" >> ~/.bash_profile
  46. fi
  47. echo "export TFB_SERVER_HOST=$SERVER_IP" >> ~/.bash_profile
  48. echo "export TFB_CLIENT_HOST=$CLIENT_IP" >> ~/.bash_profile
  49. echo "export TFB_DATABASE_HOST=$DATABA_IP" >> ~/.bash_profile
  50. echo "export TFB_CLIENT_USER=$USER" >> ~/.bash_profile
  51. echo "export TFB_DATABASE_USER=$USER" >> ~/.bash_profile
  52. echo "export FWROOT=$HOME/FrameworkBenchmarks" >> ~/.bash_profile
  53. source ~/.bash_profile
  54. # Ensure their host-local benchmark.cfg is not picked up on the remote host
  55. if [ -e "~/FrameworkBenchmarks/benchmark.cfg" ]; then
  56. echo "You have a benchmark.cfg file that will interfere with Vagrant, moving to benchmark.cfg.bak"
  57. mv ~/FrameworkBenchmarks/benchmark.cfg ~/FrameworkBenchmarks/benchmark.cfg.bak
  58. fi
  59. # Setup hosts
  60. echo "Setting up convenience hosts entries"
  61. echo $DATABA_IP TFB-database | sudo tee --append /etc/hosts
  62. echo $CLIENT_IP TFB-client | sudo tee --append /etc/hosts
  63. echo $SERVER_IP TFB-server | sudo tee --append /etc/hosts
  64. # Update hostname to reflect our current role
  65. if [ "$ROLE" != "all" ]; then
  66. echo "Updating hostname"
  67. echo 127.0.0.1 `hostname` | sudo tee --append /etc/hosts
  68. myhost=TFB-${ROLE}
  69. echo $myhost | sudo tee --append /etc/hostname
  70. sudo hostname $myhost
  71. echo Updated /etc/hosts file to be:
  72. cat /etc/hosts
  73. fi
  74. # Workaround mitchellh/vagrant#289
  75. echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | sudo debconf-set-selections
  76. # Install prerequisite tools
  77. echo "Installing prerequisites"
  78. sudo apt-get install -y git
  79. sudo apt-get install -y python-pip
  80. # Make project available
  81. # If they synced it to /FwBm, just expose it at ~/FwBm
  82. # If they didn't sync, we need to clone it
  83. if [ -d "/FrameworkBenchmarks" ]; then
  84. ln -s /FrameworkBenchmarks $FWROOT
  85. echo "Removing installs/ and results/ folders so they do not interfere"
  86. rm -rf $FWROOT/installs $FWROOT/results
  87. else
  88. # If there is no synced folder, clone the project
  89. echo "Cloning project from TechEmpower/FrameworkBenchmarks master"
  90. git clone -b ${GH_BRANCH} https://github.com/${GH_REPO}.git $FWROOT
  91. fi
  92. sudo pip install -r $FWROOT/config/python_requirements.txt
  93. # Everyone gets SSH access to localhost
  94. echo "Setting up SSH access to localhost"
  95. ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
  96. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  97. chmod 600 ~/.ssh/authorized_keys
  98. # Enable remote SSH access if we are running production environment
  99. # Note : this are always copied from the local working copy using a
  100. # file provisioner. While they exist in the git clone we just
  101. # created (so we could use those), we want to let the user
  102. # have the option of replacing the keys in their working copy
  103. # and ensuring that only they can ssh into the machines
  104. if [ "$ROLE" == "server" ]; then
  105. # Ensure keys have proper permissions
  106. chmod 600 ~/.ssh/client ~/.ssh/database
  107. elif [ "$ROLE" != "all" ]; then
  108. # Ensure keys can be used to ssh in
  109. echo "Setting up SSH access for the TFB-server"
  110. mykey=~/.ssh/$ROLE.pub
  111. echo "Using key: "
  112. ssh-keygen -lv -f $mykey
  113. cat $mykey >> ~/.ssh/authorized_keys
  114. # Ensure keys have proper permissions
  115. chmod 600 ~/.ssh/client ~/.ssh/database
  116. fi
  117. # Setup
  118. echo "Installing $ROLE software"
  119. cd $FWROOT
  120. toolset/run-tests.py --verbose --install $ROLE --install-only --test ''
  121. # Setup a nice welcome message for our guest
  122. echo "Setting up welcome message"
  123. sudo rm -f /etc/update-motd.d/51-cloudguest
  124. sudo rm -f /etc/update-motd.d/98-cloudguest
  125. sudo mv ~/.custom_motd.sh /etc/update-motd.d/55-tfbwelcome
  126. fi