Wednesday, March 13, 2013

How to Install a ProActive Node on a Virtual Machine only accessible via the VDI image file.


If we have access to the VDI (Virtual Disk Image) file, we will be able to install ProActive and configure the VM to automatically start a ProActive Node at next boot. In order to do that, we will use the libguestfs free library. Libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images.

The following diagram shows the steps required to prepare a VM image (Linux or Windows) using libguestfs :



Fig 1. Automatic Installation Diagram


We suppose that the libguestfs is installed (or can be installed) on a controller host OS Linux Fedora 16 that will be used to prepare images.

We will follow a similar procedure between Linux and Windows OS, we will detail now this procedure for both Linux and Windows VMs. We implemented and tested successfully this procedure for a few Windows and Linux virtual machines.

The naked image is a Linux OS


We will describe all the commands used and the scripts written in order to install ProActive on a naked Linux image. The image that we used here is a Linux Ubuntu 12.10 image.
We will use libguestfs via the command guestfish. This command connects to the file system of a Virtual Machine image and allow the user to execute bash-like commands which can for example, add directories and files inside the file system, edit existing files, listing directories, modifying files permissions, etc...
Guestfish is an interactive interpreter but commands can as well be executed all-at-once by providing to the guestfish command a script. Here is the command-line that we launched in order to connect to our ubuntu image, and execute our installation procedure :

guestfish --rw -a "/home/fviale/fviale/VirtualBox VMs/ubuntu-12.10-desktop-i386.vdi" -i -f guestfish_script_linux

The guestfish_script_linux definition with the explanation of each step is shown below :

# Insure that all created files are accessible
umask 000
# Equivalent of the Linux command mkdir -p
mkdir-p /opt/tools
# Upload Java packages in the image
tgz-in jdk-7u10-linux-i586.gz /opt/tools/
# Upload ProActive Scheduling packages
tgz-in ProActiveScheduling-3.3.2_bin.tgz /opt/tools/
# Create the logs directory
mkdir-p /opt/tools/ProActiveScheduling-3.3.2_bin/.logs
# Insure the logs directory is writable
chmod 0777 /opt/tools/ProActiveScheduling-3.3.2_bin/.logs
# Copy the service definition into the
copy-in proactive-node /etc/init.d/
# Backup previous services definitions
cp /etc/rc.local /etc/rc.local.old
# Copy the rc.local file from guest to host
download /etc/rc.local /tmp/rc.local
# Remove the exit 0 from last line
! head -n -1 /tmp/rc.local > /tmp/rc.local.new
# Add service startup at boot of the image
! echo /etc/init.d/proactive-node start >> /tmp/rc.local.new
# Add the mandatory exit 0
! echo exit 0 >> /tmp/rc.local.new
# Copy the new rc.local from host to guest
upload /tmp/rc.local.new /etc/rc.local
chmod 0775 /etc/init.d/proactive-node
# Restrict service file to root only
chown 0 0 /etc/init.d/proactive-node
exit

After executing our guestfish script, our naked linux Virtual Machine now contains ProActive. It has a new service called proactive-node which will create a ProActive Node when the VM will boot.

The proactive-node service definition is shown below :
#!/bin/sh
# chkconfig: 98 02
# description: This is a daemon for automatically
# starting a proactive node
#
# processname: proactive-node
##

prefix=/usr
exec_prefix=/usr
sbindir=/usr/sbin
SCRIPT_BASE=/opt/tools/ProActiveScheduling-3.3.2_bin/bin/unix
SCRIPT_LOG_LOCATION=/opt/tools/ProActiveScheduling-3.3.2_bin/.logs/
START_UP_LOG=${SCRIPT_LOG_LOCATION}/startup
SHUT_DOWN_LOG=${SCRIPT_LOG_LOCATION}/shutdown
# Sanity checks.
# so we can rearrange this easily
RETVAL=0

start() {
echo "Starting my service "
echo " log location is:" ${START_UP_LOG}
export JAVA_HOME=/opt/tools/jdk1.7.0_10
nohup ${SCRIPT_BASE}/rm-start-node -r rmi://node0.entreprise.com:1099 >> ${START_UP_LOG} &
echo "Done starting my service! "
}

stop() {
echo "Stopping my service "
echo " log location is:" ${SHUT_DOWN_LOG}
killall -s 9 java>>${SHUT_DOWN_LOG}
echo "Done stopping my service! "
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $pidfile $processname
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$servicename ]; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
;;
esac
exit $RETVAL

At next boot, the ProActive node will be created and will connect to our resource manager : rmi://node0.entreprise.com:1099
The node will then be usable by the Resource Manager as a Linux computing resource.

The naked image is a Windows OS


Similarly to our Linux VM, we will upload ProActive binaries on the Windows VM by using guestfish. We used for the example a Windows 7 SP1 32 bits image. We run our installation procedure by the following command :

guestfish --rw -a "/home/fviale/fviale/VirtualBox VMs/Windows 7 (32)/Windows 7 (32).vdi" -i -f guestfish_script_windows

The guestfish_script_windows definition with the explanation of each step is shown below :

# creates the directory c:\tools
mkdir /tools
# upload to the VM and unpack Java Virtual Machine 1.6
tgz-in jre1.6.tgz /tools/
# upload to the VM and unpack the ProActive library
tgz-in ProActiveScheduling-3.3.2_bin.tgz /tools/
# upload the RHSrvAny program to convert any windows command to a service
upload rhsrvany.exe /tools/rhsrvany.exe
# upload a modified DOS batch file which will be used to start the node
upload start-node-with-jre.bat /tools/ProActiveScheduling-3.3.2_bin/bin/windows
# exit from the guestfish interpreter
exit

In order to add the ProActive node as a service, the RHSrvAny  tool is used to wrap as a service the command that starts the ProActive node. After we upload the tool into the VM, we will have to edit the VM’s Windows Registry in order to install our service. This is done by using another libguestfs command called virt-win-reg :

virt-win-reg --merge "/home/fviale/fviale/VirtualBox VMs/Windows 7 (32)/Windows 7 (32).vdi" service.reg

The service.reg file must contain:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\RHSrvAny]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"="c:\\tools\\rhsrvany.exe"
"DisplayName"="RHSrvAny"
"ObjectName"="LocalSystem"

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\RHSrvAny\Parameters]
"CommandLine"="c:\\tools\\ProActiveScheduling-3.3.2_bin\\bin\\windows\\start-node-with-jre.bat"
"PWD"="c:\\tools\\ProActiveScheduling-3.3.2_bin\\bin\\windows"

Since no JAVA_HOME variable is defined on the naked image, the start-node-with-jre.bat script is uploaded and used on the VM to start a node, the script sets the JAVA_HOME variable and the Resource Manager URL used :
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_32
rm-start-node.bat -r rmi://node0.entreprise.com:1099

After these steps, at next boot, the ProActive node will be created and will connect to our resource manager : rmi://node0.entreprise.com:1099
The node will then be usable by the Resource Manager as a Windows computing resource.

Appendix

Automatic Installation Diagram Legend


  1. Controller HOST: a machine on which the installation procedure will be executed. Here we suppose that the Host is a Linux machine running on Fedora. This limitation is mainly to simplify the diagram, as it is totally possible to run the automatic installation procedure from a Windows Host, but with an intermediate temporary Fedora Linux Virtual Machine (the prototype tested was actually done using this configuration).   
  2. FILES: the list of files used during the installation process, those files are supposed available in the Controller HOST or downloaded otherwise :
    1. Oracle JRE : the Java Virtual Machine that will be used to start a ProActive Node.
    2. ProActive Scheduler 3.3 : the ProActive archive.
    3. guestfish scripts : the scripts that will be executed inside the guestfish environment (see 7).
    4. RHSrvAny executable : the executable which will be used to start a ProActive Node as a service in Windows Guest VMs.
    5. Linux Service definition : a text file which will be used to create a service in Linux Guest VMs.
  3. Linux or Windows Vanilla Guest VM: we suppose clean installations of Windows or Linux Virtual Machines, without any specific software installed. The VMs are supposed to be turned off before the installation process starts, and we will do all the installation procedure using only the virtual machines VDI files.
  4. Installation Process : The installation process is here described as a flowchart
  5. Download Necessary Files : if the Files (2) are not available we download them from the network or the Internet.  
  6. Install Libguestfs : The installation relies on the libguestfs library available on linux only and easier to install on Fedora. In this step we install libguestfs, for example using yum.
  7. Connect Guestfish to the Linux or Windows VM File System : we will use the Guestfish interpreter to modify the VDI file. The first step of the procedure is to connect to the VDI file by using the guestfish command-line and thus starting a guestfish session. For example to connect to a Windows VM, we used the following command line : “guestfish --rw -a "/home/fviale/fviale/VirtualBox VMs/Windows 7 (32)/Windows 7 (32).vdi" -i”
  8. Guestfish Session : the guestfish session describes a set of steps which will be done in the guestfish interpreter. Here we will describe those steps one-by-one but we can of course automate the session by using a script.
  9. Unpack Java & ProActive archives : the first step of the installation will be to unpack the content of the ProActive archive and of the Java Virtual Machine archive in a dedicated directory inside the Windows or Linux VM. The following steps differ slightly when we operate a Linux or a Windows VM, but the general idea is the same. We will try to create a Linux or Windows service which we be launched automatically at startup. This service will start a ProActive Node that will connect automatically to a ProActive Resource Manager.
  10. Copy proactive-node linux service definition : for linux VM, we will upload the definition of the proactive-node service. The place where this service definition must be uploaded can vary from one distribution to another. In this prototype, we used a Ubuntu VM and uploaded the service definition as /etc/init.d/proactive-node.
  11. Add service to startup : we will add the proactive-node service as a startup service. We do this by editing the /etc/rc.local file inside the Linux VM.
  12. Copy RHSrvAny executable: for windows VM, similarly we will create a windows service. This is done thanks to the windows program RHSrvAny#. The RHSrvAny program converts any windows command-line to a runnable windows service, simplifying greatly the configuration necessary.
  13. Add executable as a service : the next step on the windows VM will be to edit the Windows Registry in order to add our service. This is done using a registry entry modification file service.reg and the libguestfs command virt-win-reg . For example, in our prototype, we executed the command : “virt-win-reg --merge "/home/fviale/fviale/VirtualBox VMs/Windows 7 (32)/Windows 7 (32).vdi" service.reg”
  14. Modified Windows Guest VM : After all these installation steps the Linux and Windows Virtual Machines will now have a working ProActive installation and will be available as ProActive resources.
  15. Start Linux/Windows VM : the next step will be start the Windows or Linux VM.
  16. In the guest VM runtime, the linux or windows service will be automatically started on boot.
  17. ProActive Node : the service will start a ProActive Node.
  18. Connect to Resource Manager : the ProActive Node will connect to an existing Resource Manager
Resource Manager : The ProActive Resource Manager will receive the new node and will be able to deploy computations on it using ProActive.