Sean's i/o Stream

Musings-as-a-Service

Quick Unix helper for updating Jazz profile*.ini files

  • September 30, 2011
  •   category: ibm
  • tags: automation, bash-scripting, ibm, jazz-automation-series, unix

When you are deploying to WebSphere there are a number of paths that need to be configured as fully qualified or absolute paths, since the JVM is now running from the WebSphere directory instead of the local Tomcat install. One of those paths is for the provision profiles in order to load the OSGI runtime environment from the update sites. It is not a bad practice to do this regardless as it will work anywhere once properly configured, so even for a Tomcat only install this will work just fine. I’ll show how I use it in a later post where I give an example of a shared update site location for multiple servers.

This can be a pain to update them and make sure that they have been updated correctly, hence the idea for spending a few extra minutes creating a re-usable script instead of just wasting my time doing this operation manually every time it comes up.

The script is not horribly complex, just setup a few variables about your current deployment, and it will iterate each context root and each corresponding profile*.ini file.

#!/bin/bash

## Script variables
TSTAMP=`date +%s`

## Environment variables
## TODO: Update to match your local environment.
JAZZ_HOME=/opt/IBM/3010/JazzTeamServer
JAZZ_CONF=${JAZZ_HOME}/server/conf
CONTEXT_ROOTS=(jts ccm qm rm)

function update {
    
    for i in "${CONTEXT_ROOTS[@]}"
    do
        echo "Working on context root: $i "
        
	PP_BAKS=${JAZZ_CONF}/${i}/provision_profiles.${TSTAMP}
	REPL_PATTERN=$(echo "file://$JAZZ_CONF/$i/sites" | perl -lpe 's/\//\\\//g')
	echo $REPL_PATTERN	
    
	mkdir ${PP_BAKS}

	for ppfile in ${JAZZ_CONF}/${i}/provision_profiles/*.ini
	do
	    cp ${ppfile} ${PP_BAKS}
# here is the magic, could probably be a magic one-liner		
	    cat ${PP_BAKS}/`basename ${ppfile}` | sed -e "s/file\:${i}\/sites/$REPL_PATTERN/g" > ${ppfile}
	    echo "Update diff for [${ppfile}] and [${PP_BAKS}/${ppfile}]"
	    diff ${ppfile} ${PP_BAKS}/${ppfile}
	done

    done
}

function restore {
    restore_timestamp=$1
    
    for i in "${CONTEXT_ROOTS[@]}"
    do
	restore_from_dir=${JAZZ_CONF}/${i}/provision_profiles.${restore_timestamp}
	if [ -d ${restore_from_dir} ]
	then
	    mv ${restore_from_dir} ${JAZZ_CONF}/${i}/provision_profiles
	else
	    echo "Could not restore [${restore_from_dir}], directory does not exist."
	fi
    done
}

function usage {
cat < <USAGE
	Usage statement: $0 <command> [options]
	  $0 update
	  $0 restore <timestamp>
USAGE

}

# main entry point
case "$1" in
    update)
	echo "update"
        update
        ;;
    restore)
        echo "restore to timestamp $2"
        restore $2
        ;;
    *)
        echo "Unknown input: [$0 $@]"
        usage
        ;;
esac

Well that is it, give it a try, it backs up your old files and even gives you a way to go back to them if you break something :)

Reference:
Back to Top