From dcee139e818d89df5370ba92616ab4c9cc4c0282 Mon Sep 17 00:00:00 2001
From: Yves Noirjean <yves.noirjean@id.ethz.ch>
Date: Fri, 26 Jan 2018 14:16:04 +0100
Subject: [PATCH] obis: fixed vagrant setup; added second vm for additional
 obis client

---
 src/vagrant/obis/README.md                   |  35 +++++--
 src/vagrant/obis/Vagrantfile                 | 101 ++++++++++++-------
 src/vagrant/obis/initialize/install_obis.sh  |  26 +++--
 src/vagrant/obis/initialize/setup_general.sh |   3 +
 src/vagrant/obis/initialize/setup_obis.sh    |  11 ++
 src/vagrant/obis/initialize/setup_openbis.sh |   3 +-
 6 files changed, 120 insertions(+), 59 deletions(-)
 create mode 100755 src/vagrant/obis/initialize/setup_obis.sh

diff --git a/src/vagrant/obis/README.md b/src/vagrant/obis/README.md
index a51ee548624..2110e71c42b 100644
--- a/src/vagrant/obis/README.md
+++ b/src/vagrant/obis/README.md
@@ -6,19 +6,33 @@ To help users interested in trying out _obis_, we provide a vagrant setup that c
 
 0. Download openbis from the https://wiki-bsse.ethz.ch/display/bis/Production+Releases
 1. Put the extract the openbis installer to the src/vagrant/initialize folder
-2. cd to `src/vagrant`
-3. `vagrant up` -- initialize the virtual machine
-4. `vagrant ssh`  -- log into the virtual machine
-6. install openBIS (inside the vagrant machine)
+2. cd to `src/vagrant/obis_with_openbis`
+3. `vagrant up --provision --provider virtualbox` -- initialize the virtual machine
+4. `vagrant ssh obisserver`  -- log into the virtual machine
+5. install openBIS (inside the vagrant machine)
    - `/vagrant_initialize/install_openbis.sh`
    - wait until `/home/openbis/bin/post-install/0-create-initial-users.sh` appears. This script does not automatically run for some reason. Terminate it by pressing CTRL-C
    - run `sudo -u openbis /home/openbis/bin/post-install/0-create-initial-users.sh` manually
    - enter a password for the **admin** and the **etlserver** user when asked
+6. For unknown reasons is seems to be necessary to set the etlserver password like this (otherwise AS and DSS will not be connected): `/home/openbis/servers/openBIS-server/jetty/bin/passwd.sh -P change etlserver`
 7. Edit the file `/home/openbis/servers/datastore_server/etc/service.properties`
    - look for the `etlserver` user and enter its password
    - set the hostname to localhost
-8. `exit` -- log off the virtual machine
+8. To use obis, switch to the obis user with `sudo su obis` and `cd ~obis`
+9. `exit` -- log off the virtual machine
 
+When openBIS is running it can be accessed on the host machine from `https://localhost:8443/openbis`.
+
+obis can be used as the user `obis`.
+
+There is a second VM in case a second obis client is needed:
+
+1. `vagrant ssh obisclient`
+2. `sudo su obis`
+3. `cd ~obis`
+4. Configure the openbis_url: `obis config -g openbis_url https://obisserver:8443`
+5. Use obis.
+6. `exit` -- log off the virtual machine
 
 ## obis/EasyBD Demo
 
@@ -127,14 +141,15 @@ When setting up a machine the first time, Vagrant reads a file called «Vagrantf
 ## start openBIS
 
 1. `vagrant ssh` -- to log into the virtual machine
-1. `/vagrant_initialize/start_services.sh` -- start openBIS and any other services
-1. point your browser to `https://localhost:8443/openbis/` and check whether your server is up and running. Try logging in as an admin user, for example.
-1. check the AS and DSS logs if you encounter any problems
+2. `/vagrant_initialize/start_services.sh` -- start openBIS and any other services
+3. point your browser to `https://localhost:8443/openbis/` and check whether your server is up and running. Try logging in as an admin user, for example.
+4. check the AS and DSS logs if you encounter any problems
    * `/home/openbis/bin/bislog.sh` -- openbis AS logfile
    * `/home/openbis/bin/dsslog.sh` -- datastore server DSS logfile
+5. You can access the openBIS instance at https://localhost:8443/openbis/.
 
 ## create a new user in openBIS
 
 1. point your browser to the ELN-LIMS Lab notebook running at `https://localhost:8443/openbis/webapp/eln-lims/` and log in as admin
-1. go to Utilities -> User Manager, click on the Operations dropdown and choose "ceate User"
-1. enter a username (User ID) and a password to create a new user in openBIS (this may a while)
+2. go to Utilities -> User Manager, click on the Operations dropdown and choose "ceate User"
+3. enter a username (User ID) and a password to create a new user in openBIS (this may a while)
diff --git a/src/vagrant/obis/Vagrantfile b/src/vagrant/obis/Vagrantfile
index ad0ddc3c979..7a06582f2eb 100644
--- a/src/vagrant/obis/Vagrantfile
+++ b/src/vagrant/obis/Vagrantfile
@@ -15,21 +15,6 @@ Vagrant.configure(2) do |config|
   #config.vm.box = "centos7-vbox"
   config.vm.box = "centos/7"
 
-  # Create a forwarded port mapping which allows access to a specific port
-  # within the machine from a port on the host machine. In the example below,
-  # accessing "localhost:8080" will access port 80 on the guest machine.
-  config.vm.network "forwarded_port", guest: 8443, host: 8443
-  config.vm.network "forwarded_port", guest: 8444, host: 8444
-
-  # Create a private network, which allows host-only access to the machine
-  # using a specific IP.
-  # config.vm.network "private_network", ip: "192.168.33.10"
-
-  # Create a public network, which generally matched to bridged network.
-  # Bridged networks make the machine appear as another physical device on
-  # your network.
-  # config.vm.network "public_network"
-
   # Share an additional folder to the guest VM. The first argument is
   # the path on the host to the actual folder. The second argument is
   # the path on the guest to mount the folder. And the optional third
@@ -39,31 +24,75 @@ Vagrant.configure(2) do |config|
   config.vm.synced_folder "../../../", "/vagrant_repo", type: "virtualbox"
   config.vm.synced_folder "initialize", "/vagrant_initialize", type: "virtualbox"
   config.vm.synced_folder "./", "/vagrant", type: "virtualbox"
-  config.vm.synced_folder "../../core-plugins", "/vagrant_core-plugins", type: "virtualbox"
+  #config.vm.synced_folder "../../core-plugins", "/vagrant_core-plugins", type: "virtualbox"
+
+  config.vm.define "obisserver" do |obisserver|
+
+    # Create a forwarded port mapping which allows access to a specific port
+    # within the machine from a port on the host machine. In the example below,
+    # accessing "localhost:8080" will access port 80 on the guest machine.
+    obisserver.vm.network "forwarded_port", guest: 8443, host: 8443
+    obisserver.vm.network "forwarded_port", guest: 8444, host: 8444
+
+    # Provider-specific configuration so you can fine-tune various
+    # backing providers for Vagrant. These expose provider-specific options.
+    # Example for VirtualBox:
+    #
+    obisserver.vm.provider "virtualbox" do |vb|
+      # Customize the amount of memory on the VM:
+      vb.memory = "2048"
+    end
+
+    # Install necessary packages and tools (yum commands + install conda)
+    obisserver.vm.provision :shell, inline: "/vagrant/initialize/setup_general.sh || true"
+
+    # Install openBIS
+    obisserver.vm.provision :shell, inline: "/vagrant/initialize/setup_openbis.sh || true"
+
+    # Install obis (including prereqs: python3, git, git-annex)
+    obisserver.vm.provision :shell, inline: "/vagrant/initialize/setup_obis.sh || true"
+    obisserver.vm.provision :shell, inline: "/vagrant/initialize/install_obis.sh || true"
+
+    # update /etc/hostname
+    obisserver.vm.network "private_network", ip: "172.28.128.3"
+
+    obisserver.vm.provision :shell do |sh|
+     sh.inline = "echo '127.0.0.1 obisserver' >> /etc/hosts
+     echo '172.28.128.3 obisclient' >> /etc/hosts
+     echo 'obisserver' > /etc/hostname
+     hostname `cat /etc/hostname`"
+    end
+
+  end
+
+
+  config.vm.define "obisclient" do |obisclient|
+
+    # Provider-specific configuration so you can fine-tune various
+    # backing providers for Vagrant. These expose provider-specific options.
+    # Example for VirtualBox:
+    #
+    obisclient.vm.provider "virtualbox" do |vb|
+      # Customize the amount of memory on the VM:
+      vb.memory = "1024"
+    end
 
-  # Provider-specific configuration so you can fine-tune various
-  # backing providers for Vagrant. These expose provider-specific options.
-  # Example for VirtualBox:
-  #
-   config.vm.provider "virtualbox" do |vb|
-     # Customize the amount of memory on the VM:
-     vb.memory = "2048"
-   end
+    # Install necessary packages and tools (yum commands + install conda)
+    obisclient.vm.provision :shell, inline: "/vagrant/initialize/setup_general.sh || true"
 
-  # Install necessary packages and tools (yum commands + install conda)
-  config.vm.provision :shell, inline: "/vagrant/initialize/setup_general.sh || true"
+    # Install obis (including prereqs: python3, git, git-annex)
+    obisclient.vm.provision :shell, inline: "/vagrant/initialize/setup_obis.sh || true"
+    obisclient.vm.provision :shell, inline: "/vagrant/initialize/install_obis.sh || true"
 
-  # Install openBIS
-  config.vm.provision :shell, inline: "/vagrant/initialize/setup_openbis.sh || true"
+    obisclient.vm.network "private_network", ip: "172.28.128.4"
 
-  # Install obis (including prereqs: python3, git, git-annex)
-  config.vm.provision :shell, inline: "/vagrant/initialize/install_obis.sh || true"
+    obisclient.vm.provision :shell do |sh|
+      sh.inline = "echo '127.0.0.1 obisclient' >> /etc/hosts
+      echo '172.28.128.3 obisserver' >> /etc/hosts
+      echo 'obisclient' > /etc/hostname
+      hostname `cat /etc/hostname`"
+    end
 
+  end
 
-  # update /etc/hostname
-  #vm.provision :shell do |sh|
-  #  sh.inline = "echo '127.0.0.1 appserver' >> /etc/hosts
-  #  echo 'appserver' > /etc/hostname
-  #  hostname `cat /etc/hostname`"
-  #end
 end
diff --git a/src/vagrant/obis/initialize/install_obis.sh b/src/vagrant/obis/initialize/install_obis.sh
index c0cc3c7cb8b..de6509cc1d6 100755
--- a/src/vagrant/obis/initialize/install_obis.sh
+++ b/src/vagrant/obis/initialize/install_obis.sh
@@ -1,16 +1,20 @@
 #!/bin/env bash
 
-# Install prerequisites from obis.tar.xz (not from the yum repo)
+sudo pip3 install -e /vagrant_python/PyBis/
+sudo pip3 install -e /vagrant_python/OBis/
 
-pushd .  $@ > /dev/null
-cd ~
-tar -xf /vagrant/initialize/obis_tools.tar.xz -C ./
-echo export PATH=\"/home/vagrant/obis_tools/bin:/home/vagrant/obis_tools/bin\$PATH\" >> .bashrc
-export PATH=/home/vagrant/obis_tools/bin:$PATH
-pip install -e /vagrant_python/PyBis/
-pip install -e /vagrant_python/OBis/
+sudo pip3 install pyOpenSSL
 
-cd obis_tools/bin
-ln -s ../Python-3.6/bin/obis ./
+if [ ! -L /usr/bin/git ]; then
 
-popd  $@ > /dev/null
+    pushd ~obis $@ > /dev/null
+
+    wget https://downloads.kitenet.net/git-annex/linux/current/git-annex-standalone-amd64.tar.gz
+    tar -xvvf git-annex-standalone-amd64.tar.gz
+
+    sudo ln -s /home/obis/git-annex.linux/git /usr/bin/git
+    sudo ln -s /home/obis/git-annex.linux/git-annex /usr/bin/git-annex
+
+    popd $@ > /dev/null
+
+fi
diff --git a/src/vagrant/obis/initialize/setup_general.sh b/src/vagrant/obis/initialize/setup_general.sh
index 16c0a627e56..cf0f8e8a1a6 100755
--- a/src/vagrant/obis/initialize/setup_general.sh
+++ b/src/vagrant/obis/initialize/setup_general.sh
@@ -9,3 +9,6 @@ sudo yum -y install wget
 sudo yum -y install epel-release
 sudo yum -y install unzip
 sudo yum -y install vim
+sudo yum -y install nano
+sudo yum -y install nmap
+sudo yum -y install net-tools
diff --git a/src/vagrant/obis/initialize/setup_obis.sh b/src/vagrant/obis/initialize/setup_obis.sh
new file mode 100755
index 00000000000..2b316190973
--- /dev/null
+++ b/src/vagrant/obis/initialize/setup_obis.sh
@@ -0,0 +1,11 @@
+# Create the obis user
+sudo useradd obis
+
+# obis dependencies
+sudo yum -y install gcc-c++.x86_64
+
+sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm
+sudo yum -y install python36u.x86_64
+sudo yum -y install python36u-devel.x86_64
+sudo yum -y install python36u-setuptools.noarch
+sudo easy_install-3.6 pip
diff --git a/src/vagrant/obis/initialize/setup_openbis.sh b/src/vagrant/obis/initialize/setup_openbis.sh
index 6021718d681..7301f4c7f02 100755
--- a/src/vagrant/obis/initialize/setup_openbis.sh
+++ b/src/vagrant/obis/initialize/setup_openbis.sh
@@ -4,8 +4,7 @@
 # NB openbis must be downloaded an installed separately because it is not available anonymously
 
 # Install Java
-wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.rpm"
-sudo rpm -ivh jdk-8u92-linux-x64.rpm
+sudo yum -y install java-1.8.0-openjdk.x86_64
 
 # Install postgresql
 sudo yum -y install postgresql-server postgresql-contrib
-- 
GitLab