3.6.  Automate deployment tasks with scripting.

[Note]

Automating the application deployment is something to consider if it is done more than one time. Successful automation will provide an error free and consistent application deployment approach. Most of the application deployment not only involves installing the application itself, but it also needs to create other WebSphere objects, configure the Web servers, file systems and others. These tasks can be automated using shell scripting depending on the operating systems, Java Common Language (JACL) and Jythons.

Getting started with wsadmin scripting

The WebSphere Application Server wsadmin.sh tool provides the ability to run scripts. The wsadmin tool supports a full range of product administrative activities.

The following figure illustrates the major components involved in a wsadmin scripting solution:

Figure 3.8. wsadmin scripting

wsadmin scripting


The wsadmin tool supports two scripting languages: Jacl and Jython. Five objects are available when you use scripts:

The scripts use these objects to communicate with MBeans that run in WebSphere Application Server processes. MBeans are Java objects that represent Java Management Extensions (JMX) resources. JMX is an optional package addition to Java 2 Platform Standard Edition (J2SE). JMX is a technology that provides a simple and standard way to manage Java objects.

Important: Some wsadmin scripts, including the AdminApp install, AdminApp update, and some AdminTask commands, require that the user ID under which the server is running must have read permission to the files that are created by the user that is running wsadmin scripting. For example, if the application server is running under user1, but you are running wsadmin scripting under user2, you might encounter exceptions involving a temporary directory. When user2 runs wsadmin scripting to deploy an application, a temporary directory for the enterprise application archive (EAR) file is created. However, when the application server attempts to read and unzip the EAR file as user1, the process fails. It is not recommended that you set the umask value of the user that is running wsadmin scripting to 022 or 023 to work around this issue. This approach makes all of the files that are created by the user readable by other users. To resolve this issue, consider the following approaches based on your administrative policies:

Launching wsadmin

The wsadmin.sh command file resides in the bin directory of every profile. Start wsadmin from a command prompt with the command:

profile_root/bin/wsadmin.sh
					

Note that the wsadmin command also exists in the bin directory of the install_root directory. If you start wsadmin from this location, you must be careful to specify the profile to work with in the command. If you do not specify the profile (or forget to specify it), the default profile will be chosen.

Example below illustrates how to start wsadmin. In this example, the wsadmin command is used to connect to the job manager. It is issued from the bin directory of the job manager profile, so the profile does not need to be specified. The -lang argument indicates Jython will be used (Jacl is the default):


/opt/IBM/WebSphere/AppServer/profiles/jmgr40/bin>wsadmin.sh -lang jython
WASX7209I: Connected to process "jobmgr" on node jmgr40node using SOAP 
connector
;  The type of process is: JobManager
WASX7031I: For help, enter: "print Help.help()"
wsadmin>

					

wsadmin syntax:


wsadmin.sh
        [ -h(elp)  ]
        [ -?  ]
        [ -c <command> ]
        [ -p <properties_file_name>]
        [ -profile <profile_script_name>]
        [ -f <script_file_name>]
        [ -javaoption java_option]
        [ -lang  language]
        [ -wsadmin_classpath  class path]
        [ -profileName profile]
        [ -conntype
                SOAP
                        [-host host_name]
                        [-port port_number]
                        [-user userid]
                        [-password password] |
                RMI
                        [-host host_name]
                        [-port port_number]
                        [-user userid]
                        [-password password] |
                JSR160RMI
                        [-host host_name]
                        [-port port_number]
                        [-user userid]
                        [-password password] |
                IPC
                        [-ipchost host_name]
                        [-port port_number]
                        [-user userid]
                        [-password password] |
                NONE
        ]
        [ -jobid <jobid_string>]
        [ -tracefile <trace_file>]
        [ -appendtrace <true/false>]
        [ script parameters ]        

					

Command and script invocation

The wsadmin.sh commands can be invoked in three different ways

Note: For simplicity, the examples assume that:

  1. Invoking a single command (-c)

    The -c option is used to execute a single command using wsadmin. In the example below, we use the AdminControl object to query the node name of the WebSphere server process:

    /opt/IBM/WebSphere/AppServer/profiles/jmgr40/bin>wsadmin.sh -lang jython -c 
    AdminControl.getNode()
    WASX7209I: Connected to process "jobmgr" on node jmgr40node using SOAP 
    connector
    ;  The type of process is: JobManager
    'jmgr40node'
    								

  2. Running script files (-f)

    The -f option is used to execute a script file. Example below shows a two-line Jython script named myScript.py. The script has a .py extension to reflect the Jython language syntax of the script. The extension plays no significance in wsadmin; the com.ibm.ws.scripting.defaultLang property or -lang parameter is used to determine the language used. If the property setting is not correct, use the -lang option to identify the scripting language, because the default is Jacl.

    Jython script:

    print "This is an example Jython script"
    print ""+ AdminControl.getNode()+""
    								

    Running a Jython script in wsadmin:

    /opt/IBM/WebSphere/AppServer/profiles/jmgr40/bin>wsadmin.sh -f myScript.py -lang jython
    WASX7209I: Connected to process "dmgr" on node dmgr40node using SOAP 
    connector;
     The type of process is: DeploymentManager
    This is an example Jython script
    dmgr40node
    								

  3. Invoking commands interactively

    The command execution environment can be run in interactive mode, so you can invoke multiple commands without having the overhead of starting and stopping the wsadmin environment for every single command. Run the wsadmin.sh command without the command (-c) or script file (-f) options to start the interactive command execution environment, as shown in the example below:

    /opt/IBM/WebSphere/AppServer/profiles/jmgr40/bin>wsadmin.sh -lang jython
    WASX7209I: Connected to process "dmgr" on node dmgr40node using SOAP 
    connector;
     The type of process is: DeploymentManager
    WASX7031I: For help, enter: "print Help.help()"
    wsadmin>
    								

    From the wsadmin> prompt, the WebSphere administrative objects and built-in language objects can be invoked, as shown in example below. Simply type the commands at the wsadmin> prompt:

    wsadmin>AdminControl.getNode()
    'dmgr40node'
    wsadmin>
    								

    End the interactive execution environment by typing quit and pressing the "Enter" key.

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Free SCDJWS 5.0 Guide