rollatwork
Posts: 5
Joined: Tue Aug 02, 2005 9:31 pm

Windows Service shuts down on log off!

Hi gang,

Great product. Ease-of-use was the decision maker for us.

However, we are encountering an issue with our Windows service in that every time the user logs off, the windows service unexpectedly terminates. Under what cirumstances would this occur and how can we prevent this??? HELP!

The service is configured to automatically start, and upon failure should recover. It is also configured to work under the local system account and DOESN'T interact with the desktop.

This Java app does create RMI REGISTRY on port 1199. Would this be an issue?

This is what I see in the EVENT VIEWER upon logoff:

Code: Select all

Event Type:	Error
Event Source:	Service Control Manager
Event Category:	None
Event ID:	7031
Date:		8/1/2005
Time:		11:33:14 PM
User:		N/A
Computer:	POP
Description:
The ACME service terminated unexpectedly.  It has done this 1 time(s).  The following corrective action will be taken in 60000 milliseconds: Restart the service. 
Your help is greatly appreciated!!!

Roll
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi Roll,

In order to figure out what causes this problem, could you please answer some questions.

What kind of service are we talking about? Is it a JAVA service (that runs a JAVA application) or an usual Win32 service?

If it is a JAVA service, the main class of the application should provide a static method that will stop the service. If this function is not provided the service terminates unexpectedly.

For more information on this topic please visit:
http://www.advancedinstaller.com/user-g ... rvice.html

All the best,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
rollatwork
Posts: 5
Joined: Tue Aug 02, 2005 9:31 pm

Yes, it is a JAVA service.

Yes, it is a JAVA service and it does expose the static stop method. Below is the code for class that has the psvm.

Could it be the case that we need to pass the vmarg -Xrs to our application? See description directly below (taken from http://java.sun.com/j2se/1.4.2/docs/too ... /java.html):

Reduces usage of operating-system signals by the Java virtual machine (JVM). This option is available beginning with J2SE 1.3.1.

In J2SE 1.3.0, the Shutdown Hooks facility was added to allow orderly shutdown of a Java application. The intent was to allow user cleanup code (such as closing database connections) to run at shutdown, even if the JVM terminates abruptly.

The JVM watches for console control events to implement shutdown hooks for abnormal JVM termination. Specifically, the JVM registers a console control handler which begins shutdown-hook processing and returns TRUE for CTRL_C_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT.

The JVM uses a similar mechanism to implement the pre-1.2 feature of dumping thread stacks for debugging purposes. Sun's JVM uses CTRL_BREAK_EVENT to perform thread dumps.

If the JVM is run as a service (for example, the servlet engine for a web server), it can receive CTRL_LOGOFF_EVENT but should not initiate shutdown since the operating system will not actually terminate the process. To avoid possible interference such as this, the -Xrs command-line option has been added beginning with J2SE 1.3.1. When the -Xrs option is used on Sun's JVM, the JVM does not install a console control handler, implying that it does not watch for or process CTRL_C_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT.

There are two consequences of specifying -Xrs:

* Ctrl-Break thread dumps are not available.
* User code is responsible for causing shutdown hooks to run, for example by calling System.exit() when the JVM is to be terminated.

Code: Select all

    /**
     * Bootstraps parser service application context and starts the application.
     * 
     * @param args -
     *            no arguments are used.
     */
    public static void main(final String[] args) {
        final int jreVersion = JdkVersion.getMajorJavaVersion();
        final int minVersion = JdkVersion.JAVA_14;

        if (jreVersion < minVersion) {
            System.out.println("JRE 1.4 required to run this service.");
            System.exit(1);
        }
        
        String applicationContextPath = APPLICATION_CONTEXT_XML;
        new ApplicationLauncher(applicationContextPath);
        
        while (service_running) {
            
        }
    }
    
    public static void stop() {
        if (service_running)  {
            service_running = false;
        }
    }
rollatwork
Posts: 5
Joined: Tue Aug 02, 2005 9:31 pm

BTW, the target environment that this occurs on is Windows 2000 Advanced Server.
rollatwork
Posts: 5
Joined: Tue Aug 02, 2005 9:31 pm

Voila!

Hi Ciprian,

That was it! I added -Xrs as a JVM argument for when the application is started as a Windows service.

I believe this was the key from the Sun doc:
When the -Xrs option is used on Sun's JVM, the JVM does not install a console control handler, implying that it does not watch for or process CTRL_C_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT.
Hope this helps others in the future.

Roll
rollatwork
Posts: 5
Joined: Tue Aug 02, 2005 9:31 pm

Just wanted to add that I confirmed this on Windows XP Professional and Home as well as Windows 2000 Advanced Server.

Return to “Common Problems”