2 Setting Up a WebLogic Server Instance as a Windows Service
To let in-flight work complete before the JVM stops, configure the graceful stop mode described in Enabling Graceful Shutdowns. A service has two distinct identities: the Windows account under which the service process runs and the WebLogic Server startup identity used to authenticate the server.
For each server instance that you set up as a Windows service, WebLogic Server creates a key in the Windows Registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. The registry entry contains such information as the name of the server and other startup arguments.
When you start the Windows host, the Microsoft Management Console uses the information in the Windows Registry key to invoke the weblogic.Server main class. The MMC cannot be configured to use Node Manager to start Managed Servers, therefore the Node Manager's monitoring and automatic restart features cannot be used for servers that run as a Windows service.
The following tasks set up and manage WebLogic Server instances that run as Windows services:
- Setting Up a Windows Service: Main Steps
Windows services enable you to create long-running executable applications that run in the background without any user interface. - Verifying the Setup
Use thewlsvcx64 -debugcommand to verify that the Windows service is configured correctly. - Using the Services Window to Stop or Restart a Server Instance
Use the Microsoft Management Console Services window to stop and restart a server instance. - Removing a Server as a Windows Service
You can remove a Windows service by using a script that causes the wlsvcX64 utility to remove the associated key from the Windows Registry. - Changing the WebLogic Startup Identity or Windows Service Account
Change the WebLogic startup identity through the server-specific boot identity file, or change the Windows service account through the service Log On tab.
Setting Up a Windows Service: Main Steps
Windows services enable you to create long-running executable applications that run in the background without any user interface.
You can set up a Windows service by running a server-specific script that invokes the weblogic.Server main class by using the information in the Windows registry key. Before running the server-specific script, configure the required connections and stop mode for the Administration Server and Managed Servers.
To set up a Windows service:
- Create a script that sets values for server-specific variables and then calls a WebLogic Server master script. See Creating a Server-Specific Script.
- If you are installing a Managed Server as a Windows service, add a variable to the server specific script that specifies the location of the domain's Administration Server. See Configuring a Connection to the Administration Server.
- If you set up both an Administration Server and a Managed Server to run as Windows services on the same computer, modify the WebLogic Server master script so that the Managed Server starts only after the Administration Server Windows service reports STARTED. See Requiring Managed Servers to Start After Administration Servers.
- To request a graceful shutdown when Windows stops the service, set
WLS_SERVICE_STOP_MODE=gracefuland create the per-server stop configuration file. See Enabling Graceful Shutdowns. - If you want to see the messages that a server instance prints to standard out and standard error (including stack traces and thread dumps), redirect standard out and standard error to a file. See Redirecting Standard Out and Standard Error to a File.
- If you have created additional Java classes that you want the WebLogic Server instance to invoke, add them to the server's classpath. See Adding Classes to the Classpath.
- Run the server-specific script. See Run the Server-Specific Script.
Creating a Server-Specific Script
The script that you create must set the required variables DOMAIN_NAME, USERDOMAIN_HOME, and SERVER_NAME. It calls the domain's setDomainEnv.cmd before installSvc.cmd; setDomainEnv.cmd supplies WL_HOME, JAVA_HOME, and the domain environment. The master script invokes the wlsvcX64 utility, which adds a key to the Windows Registry.
Note:
You can specify a service description by setting SERVICE_DESCRIPTION before running installSvc.cmd, or by using the wlsvcX64 option -svcdescription:<user_specified_service_description>. For information about the utility, enter:
"%WL_HOME%\server\bin\wlsvcX64.exe" -helpTo see an example of a server-specific script, refer to Example 2-1.
Configure a server-specific boot identity file before installing the service. Do not put a clear-text WebLogic password in this script. WLS_USER and WLS_PW are deprecated compatibility inputs. See Boot Identity Files.
Parent topic: Setting Up a Windows Service: Main Steps
Configuring a Connection to the Administration Server
If you want to install a Managed Server as a Windows service, you must include a variable that specifies the location of the domain's Administration Server. On its first startup, the Managed Server must contact the Administration Server to retrieve its configuration data.
The Administration Server may itself run as a Windows service. It does not need to be running while you install the Managed Server service. On its first startup, the Managed Server must be able to reach the Administration Server at ADMIN_URL to obtain its domain configuration. On later startups, a Managed Server with Managed Server Independence mode enabled can use its locally cached configuration if the Administration Server is unavailable. See Starting a Managed Server When the Administration Server Is Unavailable.
To configure a connection to the Administration Server:
Configure a server-specific boot identity file before installing the service. See Boot Identity Files.
Example 2-1 Example Script for Setting Up a Managed Server as a Windows Service
@echo off setlocal set "DOMAIN_NAME=base_domain" set "USERDOMAIN_HOME=C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain" set "SERVER_NAME=ManagedServer" set "ADMIN_URL=t3s://admin-host.example.com:9002" set "DOMAIN_PRODUCTION_MODE=true" set "USER_MEM_ARGS=-Xms128m -Xmx512m" call "%USERDOMAIN_HOME%\bin\setDomainEnv.cmd" call "%WL_HOME%\server\bin\installSvc.cmd" endlocal
Note:
To use this example script to set up an Administration Server as a Windows service, remove the ADMIN_URL variable.
If you copy and paste examples, make sure that there are no trailing spaces in them.
The example uses the default secured-production administration port. Substitute the Administration Server's configured protocol, host name, and administration/listen port. If the administration port is enabled, use t3s or https and that port (9002 by default). The service JVM must trust the Administration Server certificate, and the URL host name must satisfy certificate host-name verification. See Using Secured Production Mode.
Parent topic: Setting Up a Windows Service: Main Steps
Requiring Managed Servers to Start After Administration Servers
If you set up both an Administration Server and a Managed Server to run as Windows services on the same computer, you can specify that the Managed Server starts only after the Administration Server Windows service reports STARTED.
-
Create a backup copy of
%WL_HOME%\server\bin\installSvc.cmd. If the Administration Server service is already installed, remove it before reinstalling it. See Removing a Server as a Windows Service. -
In the final
wlsvcX64invocation ininstallSvc.cmd, insert-delay:delay_millisecondsbefore-cmdline:%CMDLINE%when installing the Administration Server service. For a two-minute fixed delay, use-delay:120000. Install the service, then remove this temporary edit from the master script.-delayis a fixed delay before the service reportsSTARTED; it is not a WebLogic health check. -
Before installing the Managed Server service, insert
-depend:"wlsvc domain-name_admin-server-name"before-cmdline:%CMDLINE%, using the exact Administration Server service name shown in Services. For example:-depend:"wlsvc myDomain_myAdminServer". Install the Managed Server service, then remove this temporary edit from the master script.The
-dependoption waits for the prerequisite Windows service to reportSTARTEDbefore starting the dependent service. You can also add-delay:delay_millisecondsfor the Managed Server service.
For information about the utility, enter:
"%WL_HOME%\server\bin\wlsvcX64.exe" -helpParent topic: Setting Up a Windows Service: Main Steps
Enabling Graceful Shutdowns
If WLS_SERVICE_STOP_MODE is unset or set to kill, stopping the Windows service terminates the server JVM. Set the mode to graceful to use WebLogic Server's built-in graceful-stop class. The class authenticates with a WLST user configuration file and its associated key file; do not store a clear-text password in the service script or stop configuration file.
Existing custom stop classes remain supported. To use one, put the class on the service classpath and set both WLS_SERVICE_STOP_MODE=custom and WLS_SERVICE_CUSTOM_STOP_CLASS=fully.qualified.ClassName in the server-specific script. The class must provide public static void stop().
Parent topic: Setting Up a Windows Service: Main Steps
Redirecting Standard Out and Standard Error to a File
By default, when you install a WebLogic Server instance as a Windows service, you cannot see the messages that the server or its JVM print to standard out and standard error.
To view these messages, you must redirect standard out and standard error to a file:
After you install the service and restart the Windows host, to view the messages that the server writes to standard out or standard error, do one of the following:
-
Make a copy of the file that you specified and view the copy. The Windows file system cannot write to files that are currently opened.
-
To view the messages as they are being printed to the file, open a command prompt and, using a DOS utility that supports the
tailcommand, entertail -fstdout-filename.
Changing the Default Rotation Criteria
By default, every 24 hours the Windows service archives messages to a file named pathname-yyyy_mm_dd-hh_mm_ss. New messages collect in the file that you specified when you set up the service.
You can change the time interval or you can set up rotation to occur based on the size of the message file instead of a time interval.
To change the default criteria at which the Windows service rotates message files:
To cause the WebLogic Server instance to print a thread dump to its standard-output destination, use the WLST threadDump command or open a command prompt and enter:
"%WL_HOME%\server\bin\wlsvcX64.exe" -dump -svcname:"wlsvc domain-name_server-name"Use the exact service name displayed in the Windows Services console. For example:
"D:\Oracle\Middleware\Oracle_Home\wlserver\server\bin\wlsvcX64.exe" -dump -svcname:"wlsvc mydomain_myserver"Parent topic: Redirecting Standard Out and Standard Error to a File
Adding Classes to the Classpath
Add application libraries after the domain environment is established and before calling installSvc.cmd. For example:
call "%USERDOMAIN_HOME%\bin\setDomainEnv.cmd"
set "CLASSPATH=C:\myLib\myJar.jar;%CLASSPATH%"
call "%WL_HOME%\server\bin\installSvc.cmd"Note:
If the Windows service classpath is too long, put the complete classpath on the first line of a protected text file as one semicolon-separated line, for example C:\secure\service-classpath.txt. In the master installSvc.cmd, temporarily replace -classpath \"%CLASSPATH%\" in the service CMDLINE with -classpath @C:\secure\service-classpath.txt. Install the service, then restore the master script. This @file behavior is specific to the WebLogic Windows service wrapper's classpath parser; the wrapper reads only the first line.
Parent topic: Setting Up a Windows Service: Main Steps
Run the Server-Specific Script
Note:
To run the server-specific script, you must log in to the Windows computer with a user account that has privileges to modify the Windows registry.
If you install the Windows service in a production environment, Oracle recommends that you do not run the service under an operating-system user account that has administrator-level privileges. See Verifying the User Account Under Which the Service Runs.
To run the server-specific script:
Parent topic: Setting Up a Windows Service: Main Steps
Verifying the Setup
Use the wlsvcx64 -debug command to verify that the Windows service is configured correctly.
To verify that you successfully set up a WebLogic Server as a Windows service, do the following:
Verifying the User Account Under Which the Service Runs
In a production environment, WebLogic Server Windows services should run under a special operating-system user account that has limited access privileges. For example, the OS user should have access privileges only to Oracle files and to your domain files. This should be the only user account that has access to these files.
To ensure that the WebLogic Server instance runs under the special OS user account:
-
Open Services in the Microsoft Management Console.
For example, from the Windows XP desktop:
-
Select the Start menu.
-
On the Start menu, select Programs > Administrative Tools > Services.
-
-
In the Services window, right click the WebLogic Server Windows service and select Properties.
-
In the Properties window, select the Log On tab.
-
Under Log on, select This account. Then enter the user name and password of the special OS user account.
-
Click OK.
Note:
When accessing network drives, the Windows service must run under the same user name as the one who shared the network drive.
Parent topic: Verifying the Setup
Using the Services Window to Stop or Restart a Server Instance
Use the Microsoft Management Console Services window to stop and restart a server instance.
By default, if you use the Microsoft Management Console to stop a server instance, it kills the server's Java Virtual Machine (JVM). If you kill the JVM, the server immediately stops all processing. Any session data is lost. If you kill the JVM for an Administration Server while the server is writing to the config.xml file, you can corrupt the config.xml file. See Enabling Graceful Shutdowns.
To stop or restart a WebLogic Server instance that is installed as a Windows service:
- Select Start > Programs > Administrative Tools > Services.
- In the Services window, find the service that you created. By default, the service name starts with
wlsvc. - Right-click the service name and select commands from the menu.
Removing a Server as a Windows Service
You can remove a Windows service by using a script that causes the wlsvcX64 utility to remove the associated key from the Windows Registry.
It does not affect the server instance's configuration that is saved in the domain's configuration file. After removing the Windows service, you can restart the WebLogic server instance with start scripts or Node Manager.
The script sets DOMAIN_NAME and SERVER_NAME to identify the exact service named wlsvc DOMAIN_NAME_SERVER_NAME. Then the script calls a master uninstall script, WL_HOME\server\bin\uninstallSvc.cmd, where WL_HOME is the directory in which you installed WebLogic Server. The master script invokes the wlsvcX64 utility, which removes a key from the Windows Registry.
To see an example of a server-specific uninstaller script, refer to Example 2-2.
To create a script for removing a Windows service that runs a WebLogic Server instance:
wlsvc myWLSdomain_myWLSserver removed.
By default, standard out is the command prompt in which you run the batch file.
Example 2-2 Script to Remove a Windows Service
@echo off setlocal set "DOMAIN_NAME=myWLSdomain" set "SERVER_NAME=myWLSserver" call "D:\Oracle\Middleware\Oracle_Home\wlserver\server\bin\uninstallSvc.cmd" endlocal
Changing the WebLogic Startup Identity or Windows Service Account
Change the WebLogic startup identity through the server-specific boot identity file, or change the Windows service account through the service Log On tab.
To change the WebLogic startup user name or password, update the server-specific boot identity file at SERVER_ROOT\security\boot.properties, where SERVER_ROOT is normally DOMAIN_HOME\servers\SERVER_NAME. Enter the valid username and password values. At the next successful server startup, WebLogic Server rewrites the values in encrypted form. Restrict permissions on the file and its containing directory to the Windows service account and required administrators. The identity must be valid in the server's security realm and authorized to start the server. See Boot Identity Files.
To change the Windows account under which the service process runs, use the service Log On tab as described in Verifying the User Account Under Which the Service Runs.
Note:
WLS_USER and WLS_PW are deprecated compatibility inputs. If an existing legacy service was installed with those values, remove and reinstall the service to change them, then remove the clear-text values from the script and migrate to a server-specific boot identity file. The legacy wrapper protects the registry value only with reversible obfuscation; do not describe it as secure encryption.