bootstrap.sh 5.5 KB

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