Browse Source

Cleanup multi bootstrap script

Hamilton Turner 11 years ago
parent
commit
73a0f96170

+ 28 - 58
toolset/deployment/vagrant-multi/Vagrantfile

@@ -11,42 +11,15 @@ Vagrant.configure("2") do |config|
     end
   end
 
-  # Add some default host entries
-  config.vm.provision :shell do |sh|
-    sh.inline = "
-      echo 127.0.0.1 `hostname` >> /etc/hosts
-      echo 172.16.0.18 TFB-dbserver >> /etc/hosts
-      echo 172.16.0.17 TFB-loadserver >> /etc/hosts
-      echo 172.16.0.16 TFB-appserver >> /etc/hosts
-      echo Updated /etc/hosts file:
-      cat /etc/hosts"
-  end
+  config.vm.define "client" do |client|
 
-  # Build the DB and client servers before the 
-  # app server
-  config.vm.define "load" do |load|
-    load.vm.hostname = "TFB-loadserver"
-    load.vm.box = "ubuntu/trusty64"
-    # virtualbox
-    #load.vm.network "private_network", ip: "172.16.16.17"
-    #load.vm.synced_folder "../../..", "/FrameworkBenchmarks"
-
-    # Configure our SSH key 
-    # (and hostname for AWS)
-    load.vm.provision "shell" do |sh|
-      sh.inline = "cat ~/.ssh/client.pub >> ~/.ssh/authorized_keys
-                   echo 'TFB-loadserver' | sudo tee /etc/hostname
-                   sudo hostname 'TFB-loadserver'"
-      sh.privileged = false
-    end
-
-    load.vm.provision "shell" do |sh|
+    client.vm.provision "shell" do |sh|
       sh.path = "bootstrap.sh"
       sh.privileged = false
       sh.args = "client"
     end
 
-    load.vm.provider :aws do |aws, override|
+    client.vm.provider :aws do |aws, override|
       aws.access_key_id = ENV['TFB_AWS_ACCESS_KEY'] 
       aws.secret_access_key = ENV['TFB_AWS_SECRET_KEY']
       aws.keypair_name = ENV['TFB_AWS_KEY_NAME']
@@ -69,26 +42,19 @@ Vagrant.configure("2") do |config|
 
       aws.instance_type = "m1.small"
     end
+
+    client.vm.provider :virtualbox do |vb, override|
+      override.vm.hostname = "TFB-client"
+      override.vm.box = "ubuntu/trusty64"
+      override.vm.network "private_network", ip: "172.16.0.17"
+      
+      override.vm.synced_folder "../../..", "/FrameworkBenchmarks"
+    end
   end
 
   # Build the DB and client servers before the 
   # app server
   config.vm.define "db" do |db|
-    db.vm.hostname = "TFB-dbserver"
-    db.vm.box = "ubuntu/trusty64"
-    
-    # Only work in virtualbox
-    #db.vm.network "private_network", ip: "172.16.0.18"
-    #db.vm.synced_folder "../../..", "/FrameworkBenchmarks"
-
-    # Configure our SSH key 
-    # (and hostname for AWS)
-    db.vm.provision "shell" do |sh|
-      sh.inline = "cat ~/.ssh/database.pub >> ~/.ssh/authorized_keys
-                   echo 'TFB-dbserver' | sudo tee /etc/hostname
-                   sudo hostname 'TFB-dbserver'"
-      sh.privileged = false
-    end
 
     db.vm.provision "shell" do |sh|
       sh.path = "bootstrap.sh"
@@ -119,24 +85,19 @@ Vagrant.configure("2") do |config|
 
       aws.instance_type = "m1.small"
     end
+
+    db.vm.provider :virtualbox do |vb, override|
+      override.vm.hostname = "TFB-database"
+      override.vm.box = "ubuntu/trusty64"
+      override.vm.network "private_network", ip: "172.16.0.18"
+      
+      override.vm.synced_folder "../../..", "/FrameworkBenchmarks"
+    end
   end
 
   # Define the app server as the primary VM
   config.vm.define "app", primary: true do |app|
-    app.vm.hostname = "TFB-appserver"
-    app.vm.box = "ubuntu/trusty64"
-    app.vm.network "private_network", ip: "172.16.16.16"
-    
-    # app.vm.synced_folder "../../..", "/FrameworkBenchmarks"
     
-    app.vm.network :forwarded_port, guest: 8080, host: 28080
-
-    # Configure our Hostname for AWS
-    app.vm.provision "shell" do |sh|
-      sh.inline = "echo 'TFB-appserver' | tee /etc/hostname
-                   hostname 'TFB-appserver'"
-    end
-
     app.vm.provision "shell" do |sh|
       sh.path = "bootstrap.sh"
       sh.privileged = false
@@ -166,6 +127,15 @@ Vagrant.configure("2") do |config|
 
       aws.instance_type = "m1.small"
     end
+
+    app.vm.provider :virtualbox do |vb, override|
+      override.vm.hostname = "TFB-server"
+      override.vm.box = "ubuntu/trusty64"
+      override.vm.network "private_network", ip: "172.16.0.16"
+      
+      override.vm.synced_folder "../../..", "/FrameworkBenchmarks"
+      override.vm.network :forwarded_port, guest: 8080, host: 28080
+    end
   end
 
 

+ 43 - 6
toolset/deployment/vagrant-multi/bootstrap.sh

@@ -6,6 +6,8 @@
 # same script can work for VirtualBox (username vagrant)
 # and Amazon (username ubuntu)
 
+
+
 # Setup some nice TFB defaults
 echo "export TFB_SERVER_HOST=172.16.0.16" >> ~/.bash_profile
 echo "export TFB_CLIENT_HOST=172.16.0.17" >> ~/.bash_profile
@@ -21,15 +23,26 @@ if [ -e "~/FrameworkBenchmarks/benchmark.cfg" ]; then
 fi
 source ~/.bash_profile
 
-# Enable SSH to localhost
-ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
-cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
-chmod 600 ~/.ssh/authorized_keys
+# Setup hosts 
+echo Setting up convenience hosts entries
+echo 172.16.0.18 TFB-database | sudo tee --append /etc/hosts
+echo 172.16.0.17 TFB-client | sudo tee --append /etc/hosts
+echo 172.16.0.16 TFB-server | sudo tee --append /etc/hosts
+
+# Update hostname to reflect our current role
+echo Updating hostname
+echo 127.0.0.1 `hostname` | sudo tee --append /etc/hosts
+myhost=TFB-${1}
+echo $myhost | sudo tee --append /etc/hostname
+sudo hostname $myhost
+echo Updated /etc/hosts file to be: 
+cat /etc/hosts
 
 # Workaround mitchellh/vagrant#289
 echo "grub-pc grub-pc/install_devices multiselect     /dev/sda" | sudo debconf-set-selections
 
 # Install prerequisite tools
+echo "Installing prerequisites"
 sudo apt-get install -y git
 sudo apt-get install -y python-pip
 
@@ -40,19 +53,43 @@ if [ -d "/FrameworkBenchmarks" ]; then
   rm -rf $FWROOT/installs $FWROOT/results
 else
   # If there is no synced folder, clone the project
+  echo "Cloning project from TechEmpower/FrameworkBenchmarks master"
   git clone https://github.com/TechEmpower/FrameworkBenchmarks.git $FWROOT
 fi
 sudo pip install -r $FWROOT/config/python_requirements.txt
 
+# Everyone gets SSH access to localhost
+echo "Setting up SSH access to localhost"
+ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
+cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
+chmod 600 ~/.ssh/authorized_keys
+
+# Ensure keys have proper permissions
+chmod 600 ~/.ssh/client ~/.ssh/database
+
+# Database and client need to add their specific keys
+# Note : this are always copied from the local working copy using a
+#        file provisioner. While they exist in the git clone we just 
+#        created (so we could use those), we want to let the user
+#        have the option of replacing the keys in their working copy
+#        and ensuring that only they can ssh into the machines
+mykey=~/.ssh/${1}.pub
+if [ -e $mykey ]; then
+  echo "Setting up SSH access for the TFB-server"
+  echo "Using key: "
+  ssh-keygen -lv -f $mykey
+  cat $mykey >> ~/.ssh/authorized_keys
+fi
+
 # Setup 
+echo "Running software installation for TFB-${1}"
 cd $FWROOT
 toolset/run-tests.py --verbose --install $1 --install-only --test ''
 
 # Setup a nice welcome message for our guest
+echo "Setting up welcome message"
 sudo rm -f /etc/update-motd.d/51-cloudguest
 sudo rm -f /etc/update-motd.d/98-cloudguest
 sudo cp /vagrant/custom_motd.sh /etc/update-motd.d/55-tfbwelcome
 
-touch ~/.firstboot
-