Sun GlassFish Enterprise Server v2.1.1 Administration Guide

Restarting Automatically on the Microsoft Windows Platform

To restart automatically on Microsoft Windows, create a Windows Service and prevent the service from shutting down when a user logs out.

Creating a Windows Service

Use the appservService.exe and appserverAgentService.exe executable files shipped with the Sun GlassFish Enterprise Server in conjunction with the Service Control command (sc.exe) provided by Microsoft.

The sc.exe command comes with Windows XP and is in the system32 subdirectory of the Windows installation directory (usually either C:\windows\system32 or C:\winnt\system32). As of this writing, the Windows 2000 sc.exe is available for download at ftp://ftp.microsoft.com/reskit/win2000/sc.zip. For more information on using sc.exe, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_scmslite.asp.

Use appservService.exe and appservAgentService.exe as follows:

C:\winnt\system32\sc.exe create service-name binPath= \"fully-qualified-path-to-appservService.exe 
\"fully-qualified-path-to-asadmin.bat start-command\" 
\"fully-qualified-path-to-asadmin.bat stop-command\"" 
start= auto DisplayName= "display-name"

Note –

There is no space between binpath and the equals sign (=). There must be a space after the equals sign and before the path.


For example, to create a service called SunJavaSystemAppServer DOMAIN1 that starts and stops the domain domain1, using a password file C:\Sun\AppServer\password.txt:

C:\windows\system32\sc.exe create domain1 binPath= 
"C:\Sun\AppServer\lib\appservService.exe \"C:\Sun\AppServer\bin\asadmin.bat 
start-domain --user admin --passwordfile C:\Sun\AppServer\password.txt domain1\" 
\"C:\Sun\AppServer\bin\asadmin.bat stop-domain domain1\"" start= auto 
DisplayName= "SunJavaSystemAppServer DOMAIN1"

To create a service that starts and stops the node agent agent1:

C:\windows\system32\sc.exe create agent1 binPath= 
"C:\Sun\AppServer\lib\appservAgentService.exe \"C:\Sun\AppServer\bin\asadmin.bat 
start-node-agent --user admin --passwordfile C:\Sun\AppServer\password.txt agent1\" 
\"C:\Sun\AppServer\bin\asadmin.bat stop-node-agent agent1\"" start= auto 
DisplayName= "SunJavaSystemAppServer AGENT1"

Note –

The start and stop commands entered as part of the binPath= parameter must have the correct syntax. To test, run the commands from the command prompt. If the commands do not properly start or stop the domain or node agent, the service does not work correctly.



Note –

Don’t use a mixture of asadmin start and stop commands and service start and stops. Mixing the two can cause the server status to be out of sync. For example, the service might not show that the component has started even though the component is not running. To avoid this situation, always use the sc.exe command to start and stop the component when using services.


If your sc.exe create command did not properly create the service, delete the service and try again. To delete the service, use the sc.exe delete "service-name" command.

Preventing the Service From Shutting Down When a User Logs Out

By default, the Java VM catches signals from Windows that indicate that the operating system is shutting down, or that a user is logging out, and shuts itself down cleanly. This behavior causes the Enterprise Server service to shut down when a user logs out of Windows. To prevent the service from shutting down when a user logs out, set the -Xrs Java VM option.

To set the -Xrs Java VM option, add the following line to the section of the as-install\domains\domain-name\config\domain.xml file that defines Java VM options:

<jvm-options>-Xrs</jvm-options>

If the Enterprise Server service is running, stop and restart the service for your changes to become effective.


Note –

In some Windows 2003 Server installations, adding the -Xrs option to the domain.xml file fails to prevent the service from shutting down. In this situation, add the option to the as-install\lib\processLauncher.xml file as follows:

<process name="as-service-name">
   ...
   <sysproperty key="-Xrs"/>
   ...