Skip to content

Step by step instructions for creating a simple genesis archetype

hoos edited this page Sep 23, 2010 · 8 revisions

In this tutorial we will create the a simple Genesis archetype for an application which is installed under a directory called helloapp. The archetype build will include tasks to create a solaris package, bundling pre, post and check installation scripts in the package.

Genesis archetypes reside in the archetypes direcory under the organisation to which they belong:

.../genesis/archetypes/MyOrganisation

Start by creating a directory named after the application installatoin driectory. In our case the helloapp will be installed under a directory called helloapp

cd .../genesis/archetypes/MyOrganisation

mkdir helloapp

Our helloapp will only have a single configuration file in it called helloapp.conf this file will contain configuration tokens from various tiers of the genesis configuration hierarchy. Create helloapp.conf file under the helloapp/bin directory:

cd helloapp

Can you figure out what command you need to issue in order to build your archetype?

mkdir bin

cd bin

touch helloapp.conf

Put the following contents into the helloapp.conf file:

# Test Common tier transcription
Common.Apache.User.Name=@Common.Apache.User.Name@

# Test Organisation tier transcription
Organisation.Name=@Organisation.Name@

# Test Project tier transcription
Project.Name=@Project.Name@

# Test Environment tier transcription 
Environment.Name=@Environment.Name@

# Test Datacentre tier transcription
Datacentre.Name=@Datacentre.Name@

# Test Rack tier transcription
Rack.Name=@Rack.Name@

# Test Server tier transcription
Server.Manufacturer=@Server.Manufacturer.Name@

Now we'll add the files required by the Solaris package which will be executed during pre and post installation. Create each file under the bin directory along side the helloapp.conf file.

.../genesis/archetypes/MyOrganisation/helloapp/bin/checkinstall

#!/bin/sh
# helloapp checkintall script.
echo "helloapp checkinstall script"

.../genesis/archetypes/MyOrganisation/helloapp/bin/postinstalll

#!/bin/sh
# helloapp postintall script.
echo "helloapp postinstall script"

.../genesis/archetypes/MyOrganisation/helloapp/bin/postremove

#!/bin/sh
# helloapp postremove script.
echo "helloapp postremove script"

.../genesis/archetypes/MyOrganisation/helloapp/bin/preinstall

#!/bin/sh
# helloapp preintall script. 
echo "helloapp preinstall script"

.../genesis/archetypes/MyOrganisation/helloapp/bin/preremove

#!/bin/sh
# helloapp preremove script. 
echo "helloapp preremove script"

The last file we need an ANT build descriptor that describes the tasks required to create the helloapp package. The build.xml file resides under the helloapp directory:

.../genesis/archetypes/MyOrganisation/helloapp/build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Genesis Enterprise Network Engineering & Systems Installation Solution.

  Genesis build.xml for helloapp 
  Author  Hussein Badakhchani
 -->

<!-- 
  Build fragment to be used for instantiating the helloapp archetype.

    Required properties:
    basedir: Should point to the current directory
    outputdir: Should point to the location where instantiated My App Server archetypes should be placed
    genesisxml: Should point to the location of the genesis xml file.
    servername: The name of the server being built.
    serverid: The fully qualified id of the server being built.
    envname: The name of the environment being built.
    envid: The fully qualified id of the environment being built.
-->
<project name="build-helloapp" default="build-helloapp-solaris-package">

  <!--
    Parameter Validation.
  -->
  <target name="validate-parameters">
    <fail unless="build.dir" message="Must specify build.dir" />
    <fail unless="genesis-xml" message="Must specify genesis-xml" />
    <fail unless="servername" message="Must specify servername" />
    <fail unless="serverid" message="Must specify serverid" />

    <fail unless="envname" message="Must specify envid" />
    <fail unless="envid" message="Must specify envid" />
  </target>  

  <!-- Calculate our derived properties -->
  <property name="server.build.dir" value="${build.dir}/helloapp/${servername}-${envname}" />
  <property name="server.helloapp.dir" value="${server.build.dir}/helloapp" />
  <property name="server.package.dir" value="${server.build.dir}-pkg" />
  <property name="jumpstart.package.dir" value="/export/jumpstart/packages/middleware" />

  <!--
    Main target.
  -->

  <target name="build-helloapp" depends="validate-parameters, clean">

    <!-- Build the filter set that we want -->
    <createfiltersetusingobjects genesisxml="${genesis-xml}" filtersetid="genesis.filter.properties">
      <object type="/Organisation/Datacentre/Rack/Server" name="${serverid}" />
      <object type="/Organisation/Project/Environment" name="${envid}" />
      <object type="/Organisation/Project" name="${projectid}" />
    </createfiltersetusingobjects>

    <!-- Load the properties of the objects associated with the build arguments. -->

    <retrieveobjectproperties genesisxml="${genesis-xml}" filtername="genesis.filter.properties" prefix="Global." />

    <echo message="Global Server Role: ${Global.Server.Role.Name}"/>
    <echo message="Global Server Role: ${Global.Server.HostName.wls04.Name}"/>

    <!-- Copy the base application configuration files into place -->
    <!-- For now filtering is turned off as we are including binary files -->
    <copy todir="${server.helloapp.dir}" includeEmptyDirs="false" filtering="on" overwrite="true">
      <filterset refid="genesis.filter.properties" />

      <!-- Base files -->
      <fileset dir="${basedir}">
        <exclude name="build-helloapp.xml" />
      </fileset>
    </copy>

    <chmod perm="u+x">
      <fileset dir="${server.helloapp.dir}/bin">
        <include name="*"/>
      </fileset>
    </chmod> 

    <findtokens failOnError="true">
      <fileset dir="${server.helloapp.dir}">
       <include name="**/*.xml" />
       <include name="**/*.conf" /> 
       <include name="**/pre*"/>
       <include name="**/post*"/>
       <include name="**/checkinstall"/>
       <include name="**/depend"/>
       <include name="**/*.sh" /> 
       <include name="**/*install" /> 
       <include name="**/*.py" /> 
       <include name="**/*.properties" />
      </fileset>
    </findtokens>
  	
  </target>
	
  <target name="package-helloapp" depends="build-helloapp,build-helloapp-solaris-package" />
    <echo message="package My App" />

    <!-- Builds the helloapp solaris package -->

    <target name="build-helloapp-solaris-package" depends="build-helloapp,os-check" if="isSolaris">

    <property name="pkgname" value="JEEAPP1.2.${Global.Server.Architecture.Name}.${envname}.${Global.Server.PlatformGroup.Name}.${Global.Server.HostName.nodename.Name}"/>
    <echo message="${pkgname}"/>
    <pkginfo
       workdir="${server.package.dir}"
       name="JEEAPPConfiguration-${envname}"
       architecture="${Global.Server.Architecture.Name}"
       longname="JEEAPP Server Configuration for ${servername}"
       version="6.2"
       vendor="VocaLink"
       pstamp="20th August 2008"
       email="middleware.services@vocalink.com"
       basedir="/" />

     <!-- Copy pre, post and checkinstall scripts to the package directory. -->
     <copy todir="${server.package.dir}">
       <fileset dir="${server.helloapp.dir}/bin">
         <include name="pre*"/>
         <include name="post*"/>
         <include name="check*"/>
         <include name="depend"/>
       </fileset>
     </copy>

     <!-- Build the base package prototype -->
     <pkgproto
       srcdir="${server.build.dir}" workdir="${server.package.dir}"
       pkginstallbase="/fs01/app/release" />

     <!-- helloapp specific protoype changes -->

     <exec dir="${server.package.dir}" executable="sed" input="${server.package.dir}/prototype.home" output="${server.package.dir}/prototype.genesis">
       <arg value="s/genesis genesis/bin bin/g" />
     </exec>
     <exec dir="${server.package.dir}" executable="sed" input="${server.package.dir}/prototype.genesis" output="${server.package.dir}/prototype">
         <arg value="s/\/fs01\/app 0755 genesis genesis/\/fs01\/app 0755 root other/g" />
     </exec>

     <pkgmk
       name="JEEAPPConfiguration-${envname}"
       workdir="${server.package.dir}"
       pkgname="${pkgname}" />
      
     <move file="${server.package.dir}/${pkgname}.pkg" todir="${jumpstart.package.dir}"/>

  </target>

  <target name="os-check">
    <condition property="isSolaris">
      <os name="SunOS" />
    </condition>
  </target>

  <target name="clean">
    <delete dir="${server.build.dir}" />

  </target>

</project>

Finally we need to register the archetype with Genesis. Edit the genesis.xml file:

.../genesis/genesis.xml

Add the following xml stanza:

<!--

  helloapp archetype a simple test archeytpe.

-->

<archetype name="helloapp" buildfile="archetypes/Vocalink/helloapp/build.xml">

  <operation name="build" target="build-helloapp" />

  <operation name="package" target="package-helloapp" />

  <requires type="/Organisation/Datacentre/Rack/Server" qnameproperty="serverid" nameproperty="servername" />

  <requires type="/Organisation/Project" qnameproperty="projectid" nameproperty="projectname" />

  <requires type="/Organisation/Project/Environment" qnameproperty="envid" nameproperty="envname" />

</archetype>

Clone this wiki locally