Example script package to install an application

This script installs an existing application in a user-specified location. The location can be either on the file system, or at some remote location. The wsadmin tool installs the application. You can pass in installation arguments during deployment.

Script variables

There are two parameters that are part of this script package.
APP_LOCATION:
Required. The location of the application. The location of the application can be either a file system location or remote location over http or https.
INSTALL_ARGS:
Optional. Install arguments for the AdminApp.install() wsadmin command. The default command is "AdminApp.install(appLocation, '[-usedefaultbindings]'). Other arguments can be supplied using this variable. An example value for this variable is "-usedefaultbinding -server myServer -appName MyApp". If the application is remote, it is copied to the current working directory before the installation command is started.

cbscript.json example

[
  {
      "name": "Install application",
      "version": "1.0.0",
      "description": "This script package installs the specified application",
      "command": "/bin/sh ${WAS_PROFILE_ROOT}/bin/wsadmin.sh",
      "log": "${WAS_PROFILE_ROOT}/logs/wsadmin.traceout",
      "location": "/opt/tmp/installapp",
      "timeout": "0",
      "commandargs": "-lang jython -f /opt/tmp/installapp/install_app.jy $APP_LOCATION $INSTALL_ARGS",
      "type": "APPLICATION",
      "keys":
      [
         {
          "scriptkey": "APP_LOCATION",
     	  "scriptvalue": ""
         },
         {
          "scriptkey": "INSTALL_ARGS",
     	  "scriptvalue": ""
         }
      ]
  }
]

Example script

Note: This example script is designed only for version 7.0.0.x virtual system patterns.
import urllib

from java.io import File
from java.lang import Boolean
from java.lang import String
from java.net import URL

def download(url):
	fileLocs = String(url).split('/')
	lastPart = fileLocs[len(fileLocs) - 1]
	file = File(lastPart)
	file.createNewFile()
	newFileLoc = file.getAbsolutePath()
	urllib.urlretrieve(url, newFileLoc)
	return newFileLoc

def copyZip(binURL):
	binURL = str(binURL)
	url = None;
	fileRemote = Boolean.FALSE
	appFileLoc = ''
	try:
		url = URL(binURL)
		fileRemote = Boolean.TRUE
	except:
		pass

	if fileRemote:
		print 'Start retrieval of ' + binURL
		appFileLoc = download(str(binURL))
			             
        else:
		print 'File already local ' + binURL
		appFileLoc = File(binURL).getAbsolutePath()

        return appFileLoc

binURL = sys.argv[0]
installArgs = '[-usedefaultbindings]'
if len(sys.argv) == 2:
	installArgs = '[' + sys.argv[1] + ']'

appLocation = copyZip(binURL)
AdminApp.install(appLocation, installArgs)
AdminConfig.save()