Revenera logo

Let us consider the following scenario. You have built a virtual appliance using InstallAnywhere 2012 Enterprise Edition with Cloud Pack. You have deployed the virtual appliance on VMware vSphere server and have switched it on. When the end user logs in to the appliance for the first time you would like to run certain scripts, for example, a script to install and configure an Apache server so that the end user of your virtual appliance can set the user name and password for the server. How does one do it? Consider another situation where you would like to run certain scripts every time you boot the virtual appliance, for example, starting and stopping operating system services, setting the default run level for these services, or downloading a file from a remote server. Is there any way to do so?

The answer to both the questions above is yes. InstallAnywhere 2012 Enterprise Edition with Cloud Pack not only lets you run executable scripts each time you power on your virtual appliance, but also every time you log in to the appliance. And the good thing about this is that you can make them work on both VMware vSphere 5 and Amazon EC2 hypervisors.

What Are Boot and Login Scripts?

Boot and login scripts are pretty straight forward. Any executable script that gets executed every time an end user boots (powers on) the virtual appliance is a boot script. The scripts that are run each time an end user logs into the appliance are login scripts.

Creating and Configuring Boot and Login Scripts

The shell scripts that are required to be run at boot or login time should be specified in the InstallAnywhere 2012 Advanced Designer, as shown in the following screen shot.

 

Navigate to Build Appliances | VM Configuration | Script Info tab and populate the following fields:

  1. First Boot Script

    Choose the executable script that you would like to run when the virtual appliance is powered on the first time.

  2. First Login Script

    Choose an executable script that should get executed the very first time an end user logs in to your virtual appliance.

  3. Subsequent Boot Script

    Choose the executable script that you would like to run every other time, i.e., every subsequent time the virtual appliance is powered on.

  4. Subsequent Login Script

    Choose an executable script that should get executed every other time, i.e., every subsequent time an end user logs in to your appliance.

In this blog I intend to demonstrate the usage of boot and login scripts for Ubuntu and CentOS virtual appliances.

Format of Boot and Login Scripts

All valid executable scripts for Ubuntu and CentOS are supported by InstallAnywhere 2012 Enterprise Edition with Cloud Pack. However, there are certain restrictions on the contents of boot scripts.

Restrictions on Boot Scripts

There are a couple of restrictions on the way the boot scripts should be written:

    • They should not contain any command that requires any sort of user interaction, since the system is still powering on at boot time.
    • These scripts cannot output any text on the Ubuntu or CentOS console. However, if you wish to log the output of your executable script, you can always redirect them to a log file. These logs will be available once the virtual appliance is powered on.

 

Examples

Let me give you an example of how to write a boot/login script for installing a LAMP stack on an Ubuntu virtual appliance.

A LAMP stack is a group of open source software; the acronym refers to Linux, Apache, MySQL, and PHP. Since installation of the Apache, MySQL, and PHP components requires user interaction in the form of keyboard input, we have to configure the installation process in the login script of the virtual appliance. Here is how you can write the script (say, lamp.sh):

#!/bin/sh

#This script installs a LAMP stack on my Ubuntu virtual appliance

 

#Update the package index

apt-get update

 

#Install Apache server

apt-get install apache2

 

#Install MySQL with PHP

apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

#Activate MySQL

mysql_install_db

#Run MySQL set up script

/usr/bin/mysql_secure_installation

 

#Install PHP

apt-get install php5 libapache2-mod-php5 php5-mcrypt

 

#Start the Apache server

/etc/init.d/apache2 start

 

exit 0

In the First Login Script field ( Build Appliances | VM Configuration | Script Info tab), enter the location of lamp.sh, and rest assured that this script will get executed when end users log in to your Ubuntu virtual appliance for the first time. This script will also enable the end users to configure information such as the user name, password, and port number, for the servers being installed.

It is quite evident that the moment you restart the virtual appliance, you will have to restart both the Apache and the MySQL servers. This job can be easily done by writing a small executable script and by specifying its location in the Subsequent Boot Script field. Here is an example of this script for an Ubuntu virtual appliance:

#!/bin/sh

 

#Start MySQL server

/etc/init.d/mysql start

 

#Start apache server

/etc/init.d/apache2 start

 

exit 0

 

Consider another example where you would like to download some documentation related to your virtual appliance from a remote HTTP server and store it to some location. You can set up your executable script in the following way:

#!/bin/sh

#Navigate to the location where the file has to be downloaded

cd /MY_WORK_DIR/Docs

#Download the file and store it at the above location

wget http://115.65.92.1/docs/MyVAppDocumenation.doc

exit 0

Follow the examples above to configure your boot scripts in a similar way. Take care though that you don’t put any commands involving user interaction in your boot scripts.


You may also like: Now Boarding: InstallAnywhere Flight 101 to Cloud and Virtual Environments

To learn more about the latest features in InstallAnywhere, view the What’s New in InstallAnywhere 2012 Webinar.

InstallShield icon

InstallShield

Create native MSIX packages, build clean installs, and build installations in the cloud with InstallShield from Revenera.