[ Team LiB ] Previous Section Next Section

Best Practices for Command-Line Interface Administration

All weblogic.Admin commands return a value of 0 in case of success and 1 in case of failure. The return value can be checked in DOS scripts with the variable ERRORLEVEL.

Here is an example of such usage:


java weblogic.Admin -url t3://localhost:7001 -username %1 -password %2 CONNECT
if ERRORLEVEL 1 echo Server is down

Using scripts and a command-line interface greatly simplifies Weblogic Server administration. When you want to stop a managed server, it is much more efficient to open a link from the Program Manager to your stopWLS.cmd file than to open up a browser, navigate through the interface, and stop the server.

Command scripts make the commands much more manageable and efficient. One such script that you'll want to create right away is one that gracefully shuts down WebLogic Server. Using Ctrl+C is essentially a FORCESHUTDOWN and, as previously stated, can cause unexpected results such as rollbacks and session loss. The contents for stopWLS.cmd are presented in Listing 38.7.

Listing 38.7 stopWLS.cmd
echo on
@rem set environment variable for WebLogic Home
set WL_HOME=F:\bea\weblogic81
@rem set the environment
call %WL_HOME%\server\bin\setWLSEnv.cmd
@rem Run the Administration Command
java weblogic.Admin -url t3://localhost:7001 -username %1 -password %2 SHUTDOWN

To save yourself the step of having to open a command-window, create a shortcut for the stopWLS.cmd file and place it in your Program Manager group for WebLogic 8.1, alongside your startWebLogic.cmd link. Now whenever you want to gracefully shut down your WebLogic Server, you can do it with the click of a single icon.

Try using Ant tasks, which are portable across different operating systems. However, some system administrators are more comfortable in shell scripts or command scripts in which they do not need to have knowledge of Java and Ant.

CAUTION

Usernames and passwords should not be stored in the scripts.


    [ Team LiB ] Previous Section Next Section