Scripts to Install and start websphere server

ibm websphere
Below script shows how we can install an application and start an application server using JACL scripts.

#---------------------------------------------------------------------------
#-- Install and start an application on a new server 
#---------------------------------------------------------------------------
# Initialize global variables to be used in creating server and installing application. Change these values to customerize for your environment.
set nodeName myNode

set serverName myServer
set appName myApp
set earFile /myEar/myApp.ear

# check if server of the same name already exists
puts "Check if a server with the name $serverName already exists"
set serverObject [$AdminConfig getid /Node:$nodeName/Server:$serverName/]
if {[llength $serverObject] != 0} {
puts "Error: server $serverName already exists on node $nodeName. Rerun the script with a different server and/or node name."
exit
}

# check if this is an existing node name
puts "Check if there is an existing node $nodeName"
set nodeObject [$AdminConfig getid /Node:$nodeName/]
if {[llength $nodeObject] == 0} {
puts "Error: node $nodeName does not exist in the current cell"
exit
}

# use default template to create the new server
puts "Creating a new server $serverName"
set attrs [list [list name $serverName]]
set myServerObject [$AdminConfig create Server $nodeObject $attrs]
# check if application with the same name already exists
if {[llength $appName] != 0} {
puts "Check if application with the same name $appName already exists"
set existingApps [$AdminApp list]
if {[regexp $appName $existingApps] == 1} {
puts "Error: application with the same name $appName already exists"
exit
}
}

# check if application file is set
puts "Check if application file is specified"
if {[llength $earFile] == 0} {
puts "Error: application file name is not specified"
exit
}

# install a new application
puts "Installing a new application $appName"
set options [list -node $nodeName]
lappend options -server $serverName
if {[llength $appName] != 0} {
lappend options -appname $appName
}
$AdminApp install $earFile $options

puts "Saving the configuration"
$AdminConfig save

# if it is a network deployment environment, perform a node sync as necessary
puts "Check for network deployment environment"
set nodeSync [$AdminControl queryNames type=NodeSync,node=$nodeName,*]
if {[llength $nodeSync] == 0} {
puts "NodeSync MBean is not available, assuming it is not network deployment environment"
} else {
# perform a node sync to update the configuration if the serverStartupSyncEnabled is set to false
set enabled [$AdminControl getAttribute $nodeSync serverStartupSyncEnabled]
if {$enabled == "false"} {
puts "Performing a node sync on $nodeName"
$AdminControl invoke $nodeSync sync
puts "Done with node sync"
}
}

# start the new server which in turn will start the new application installed on this server
puts "Starting the new server $serverName"
$AdminControl startServer $serverName $nodeName

puts "Done"
#---------------------------------------------------------------------------
#-- Install and start an application on a new cluster 
#---------------------------------------------------------------------------

# Initialize global variables to be used in creating cluster and installing application
set cellName myCell
set nodeList {myNode myNode2}
# serverList and weightList have to be provided in a nested list format, i.e. one nested list per node specified in nodeList.
#Even if there is only one cluster in a node, it has to be provided as a list.

set serverList {{myClusterServer1 myClusterServer2} {myClusterServer3}}
set weightList {{10 10} {20}}
set clusterName myCluster
set appName myClusterApp
set earFile /myEar/myClusterApp.ear

# check if this is an existing cell
set cellObject [$AdminConfig getid /Cell:$cellName/]
if ([llength $cellObject] == 0) {
puts "Error: cell $cellName does not exist in the configuration"
exit
}
# check if cluster of the same name already exists
puts "Check if a cluster with the name $clusterName already exists"
set clusterObject [$AdminConfig getid /Cell:$cellName/ServerCluster:$clusterName/]
if {[llength $clusterObject] != 0} {
puts "Error: cluster $clusterName already exists on cell $cellName. Rerun the script with a different cell and/or cluster name."
exit
}
set nodeIndex 0
# check if specified nodes and server names exist
foreach node $nodeList {
# check if node exists
puts "Check if node $node exists"
set nodeObject [$AdminConfig getid /Cell:$cellName/Node:$node/]
if {[llength $nodeObject] == 0} {
puts "Error: node $node does not exist in the cell $cellName"
exit
}
set sList [lindex $serverList $nodeIndex]
foreach server $sList {
puts "Check if server $server exists on node $node"
set serverObject [$AdminConfig getid /Cell:$cellName/Node:$node/Server:$server/]
if {[llength $serverObject] != 0} {
puts "Error: server $server already exists on node $node"
exit
}
}
incr nodeIndex
}

# create a new cluster
puts "Creating a new cluster $clusterName"
set nameAttr [list name $clusterName]
set descAttr [list description "My cluster"]
set stateMAttr [list stateManagement [list [list initialState STOP]]]
set attrs [list $nameAttr $descAttr $stateMAttr]
set clusterObject [$AdminConfig create ServerCluster $cellObject $attrs]

# create new cluster member
set nodeIndex 0
foreach node $nodeList {
set nodeObject [$AdminConfig getid /Cell:$cellName/Node:$node/]
set servers [lindex $serverList $nodeIndex]
set weights [lindex $weightList $nodeIndex]
set serverIndex 0
foreach server $servers {
set nameAttr [list memberName $server]
set weightAttr [lindex $weights $serverIndex]
puts "Creating new cluster member $server"
set attrs [list $nameAttr $weightAttr]
$AdminConfig createClusterMember $clusterObject $nodeObject $attrs
incr serverIndex
}
incr nodeIndex
}

# check if application with the same name already exists
if {[llength $appName] != 0} {
puts "Check if application with the same name $appName already exists"
set existingApps [$AdminApp list]
if {[regexp $appName $existingApps] == 1} {
puts "Error: application with the same name $appName already exists"
exit
}
}

# check if application file is set
puts "Check if application file is specified"
if {[llength $earFile] == 0} {
puts "Error: application file name is not specified"
exit
}

# install a new application
puts "Installing new application $appName onto cluster $clusterName"
set options [list -cluster $clusterName]
if {[llength $appName] != 0} {
lappend options -appname $appName
}
$AdminApp install $earFile $options

puts "Saving the configuration"
$AdminConfig save

# if it is a network deployment environment, perform node sync as necessary
puts "Check for network deployment environment"
foreach node $nodeList {
set nodeSync [$AdminControl queryNames type=NodeSync,node=$node,*]
if {[llength $nodeSync] == 0} {
puts "NodeSync MBean is not available, assuming it is not network deployment environment"
break
} else {
# perform a node sync to update the configuration if the serverStartupSyncEnabled is set to false
set enabled [$AdminControl getAttribute $nodeSync serverStartupSyncEnabled]
if {$enabled == "false"} {
puts "Performing a node sync on node $node"
$AdminControl invoke $nodeSync sync
puts "Done with node sync on node $node"
}
}
}

# look for ClusterMgr MBean to refresh the list of clusters
set runningClusterMgr [$AdminControl completeObjectName type=ClusterMgr,cell=$cellName,*]
if {[llength $runningClusterMgr] == 0} {
puts "Not able to find ClusterMgr MBean. You have to start the cluster $clusterName manually"
} else {
puts "Refresh the list of clusters to load the new cluster $clusterName"
$AdminControl invoke $runningClusterMgr retrieveClusters
# locate the cluster MBean for the new cluster
set runningCluster [$AdminControl completeObjectName type=Cluster,name=$clusterName,*]
puts "Starting the new cluster $clusterName"
$AdminControl invoke $runningCluster start
set state [$AdminControl getAttribute $runningCluster state]
puts -nonewline "Waiting for cluster to start .."
while {$state != "websphere.cluster.running" && $state != "websphere.cluster.stopped"}
# sleep for 100 milliseconds
after 100
set state [$AdminControl getAttribute $runningCluster state]
puts -nonewline ".."
}

 puts "\nCluster state is $state"
 }
 
 puts "Done"

In case of any ┬ęCopyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply