Version 1 (modified by ibaldin, 7 years ago)


Using Velocity templates in post-boot scripts


Post-boot scripts can be added to any node within a slice. They will be executed immediately after boot is complete. These scripts are processed by a Velocity template engine that allows for substitution of user-generated element names. This document explains the use of the templating features in post-boot scripts.


For added functionality, ORCA uses velocity templates to create the scripts. See the user's guide for details about Velocity.

ORCA templates follow the Velocity syntax which can be used to replace several key pieces of data that are assigned by ORCA. Specifically, there are one or more arrays that contains the IP addresses assigned to each instance. There is one array of IP addresses for each group. Each array of IP addresses is referenced using the name provided to Flukes for the group. In addition, there is a variable called $MY_ADDR_INDEX that is the index of the IP address of the current instance within its group's array of IP addresses. All arrays of IP addresses are accessible from any post boot script in the current request.

The following is an example post boot script that adds an entry to the /etc/hosts file for each of the instances in the request and sets the hostname of each instance to an appropriate value. In this particular example, the first instance is assumed to be a master node named "master" while the remaining nodes are named "worker1", "worker2", etc.. The string "Group1" was used as the group name.

   # Test script 
   echo "Hello from post boot script"
   echo $Group1.get(0) master  >> /etc/hosts 
#set ( $size = $Group1.size() - 1 )
#foreach ( $i in [1..$size] )
   echo $Group1.get($i) worker$i >> /etc/hosts
#if ( $MY_ADDR_INDEX == 0)
   echo master > /etc/hostname
   echo worker$MY_ADDR_INDEX > /etc/hostname

WARNING: due to a known bug, all script lines (not template lines) except for the first (which typically just says "#!/bin/bash" or similar) must start with white space (e.g. a tab) in order to be properly interpreted (as in the example above).


Experimenters can use the neuca tools inside their VM image to debug problems with post-boot script templates. Specifically invoking

$ neuca-user-script

will show the state of the post-boot script after Velocity processing and should help pinpoint any problems in macro substitutions in the template.