Writing a WebLogic Startup Script
One of the most common ways to start WebLogic Server is by using a startup script. A startup script is nothing more than an ordered list of commands that would normally be issued at the Windows or UNIX command prompt.
Starting WebLogic Server from an existing startup script has several advantages:
- There is no need to enter the admin ID and password each time.
- Other related commands, such as mapping network drives, can automatically be performed as part of the script.
- The script can be started easily by other automated processes.
However, using a custom startup script has some potential disadvantages, such as the following:
- If the admin password is embedded in the script, the script is less secure than the supplied script.
- It takes time to properly create a startup script.
- A user must be logged on to the server to run the startup script.
You begin finding out about startup scripts by examining the standard startup script that WebLogic creates for new server instances.
The standard startup script
Fortunately, you don’t need to build your startup script from scratch. Every time you create a new server instance, a standard startup script is created for you. You can modify this script as you see fit. The standard startup script is named startWebLogic.cmd if you’re running Windows and startWebLogic.sh if you’re running UNIX. The contents of the Windows and UNIX startup scripts are similar.
Listing 1 shows an example of the standard startup script generated by WebLogic for the Windows operating system.
Listing 1: Typical Windows WebLogic Startup Script
@rem Set SERVER_NAME to the name of the server you want to
@rem Set WLS_USER equal to your system username and
@rem WLS_PW equal to your system password for no username
@rem and password prompt during server startup. Both are
@rem required to bypass the start prompt. This is not
@rem recommended for a production environment.
@rem Set Production Mode. When this is set to true,
@rem the server starts in production mode. When
@rem set to false, the server starts in development
@rem mode. If it is not set, it will default to false.
@rem Set JAVA_OPTIONS to the java flags you want to pass to
@rem the vm. i.e.:
@rem set JAVA_OPTIONS=-Dweblogic.attribute=value
@rem Set JAVA_VM to the java virtual machine you want to run.
@rem For instance:
@rem set JAVA_VM=-server
@rem Set MEM_ARGS to the memory args you want to pass to
@rem java. For instance:
@rem set MEM_ARGS=-Xms32m -Xmx200m
@rem Call Weblogic Server
The startup script is not too difficult to understand. Lines that begin with @rem are remarks, or comments, added so you can understand what the different command lines do. The lines that do not begin with @rem are interpreted by WebLogic and are used to start the server.
Through the startup script, you set environment variables that control the launch and runtime operation of WebLogic Server. To create a customized startup script, you begin by modifying these variables in the standard script.
If additional commands must be executed before the server starts, simply modify the script to include the commands. A script is executed line by line, so make sure that the commands appear in the script file before the end, where the startWLS.cmd file is invoked. (This is the script command to start WebLogic Server.)
Constructing your own startup script
In the preceding section, you saw that WebLogic creates a standard script that you can modify. In this section, you find out how to set the various environment variables in the script. The first step in modifying a startup script is to load it into a text editor. A startup script doesn’t require a special program for editing; it is nothing but a plain text file. In Windows, you can do your editing in a program such as Notepad. In UNIX, you can use a program such as vi or pico. However, you’re not limited to using these programs; any text editor will suffice.
If you’re not familiar with the UNIX environment, you will probably find the vi editor confusing. The pico editor more closely resembles Windows Notepad. To use the pico editor from UNIX, you type the pico command followed by the name of the file you’re editing.
For example, the following command edits the web.xml file using pico as your editor:
Now that the startup script is opened, you can make your desired changes. Table 1 lists some of the environment variables you can modify.
Table 1: WebLogic Environment Variables
What It Is
The Java command-line options for running the server.
The Java argument specifying the VM to run (such as -server or -client) (hotspot is deprecated).
The variable to override the standard memory arguments passed to Java.
The operating mode for the server. Specify True for production mode servers and False for development mode.
The WebLogic user password used to start the server.
The WebLogic user ID used to start the server.
Usually, you will not want to change the default virtual machine that Java is using. Java achieves performance gains by compiling Java instructions into the native instruction set of the computer. If you specify the -classic option for JAVA_VM, no compiling is used. If you specify the -server or -client option, a compiler optimized for server or client operations, respectively, is used. There’s no reason to ever run WebLogic using the -client option.
In Table 1, look at the STARTMODE variable and the mention of development and production modes. When you want to know whether something is working properly, use development mode because it helps you track down problems. Production mode reports fewer errors and generally runs faster.
A side effect of development mode is that you’ll need to clear the logs more often and pay more attention to your server. Production mode also preloads more of the server, so if you’re restarting the server frequently, you’ll want to use development mode.
You can also specify the user ID and password when staring the server. To specify the user information, you should use the WLS_PW and WLS_USER variables. This will prevent WebLogic from prompting you each time it starts. The JAVA_OPTIONS variable allows you to pass additional parameters to the Java virtual machine. The MEM_ARGS variable allows you to request additional memory. The format for MEM_ARGS follows:
This command specifies 128MB of initial memory size and 512MB as the maximum memory size.
If you get out-of-memory errors in WebLogic, you should adjust the MEM_ARGS variable.