|
From: Sandeep K. <san...@vi...> - 2004-01-09 22:03:25
|
Hi, In regards to the Windows service failure recovery discussion, I tried another product called FireDaemon (http://www.firedaemon.com) This product exits appropriately and triggers the Windows service failure recovery hooks like running external programs. The following are some useful findings using sc.exe in windows command prompt. -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< C:\Sandeep\java_service\bin>sc qfailure testwrapper [SC] GetServiceConfig SUCCESS SERVICE_NAME: testwrapper RESET_PERIOD : 60 seconds REBOOT_MESSAGE : COMMAND_LINE : c:\sandeep\sendmail.exe /SFILE:c:\sandeep\wrapper-sendmail.xml FAILURE_ACTIONS : RUN PROCESS -- Delay = 20000 milliseconds RUN PROCESS -- Delay = 20000 milliseconds RUN PROCESS -- Delay = 20000 milliseconds C:\Sandeep\java_service\bin>sc qfailure testfiredaemon [SC] GetServiceConfig SUCCESS SERVICE_NAME: testfiredaemon RESET_PERIOD : 60 seconds REBOOT_MESSAGE : COMMAND_LINE : c:\sandeep\sendmail.exe /SFILE:c:\sandeep\firedaemon-sendmail.xml FAILURE_ACTIONS : RUN PROCESS -- Delay = 20000 milliseconds RUN PROCESS -- Delay = 20000 milliseconds RUN PROCESS -- Delay = 20000 milliseconds -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< C:\Sandeep\java_service\bin>sc query testwrapper SERVICE_NAME: testwrapper TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 1067 (0x42b) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\Sandeep\java_service\bin>sc query testfiredaemon SERVICE_NAME: testfiredaemon TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 1067 (0x42b) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 C:\Sandeep\java_service\bin> -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< MyWrapperListener.java ====================== import org.tanukisoftware.wrapper.WrapperManager; import org.tanukisoftware.wrapper.WrapperListener; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: XXXXXXXX </p> * @author Sandeep Khanna * @version 1.0 */ public class MyWrapperListener implements WrapperListener { /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ private MyWrapperListener() { } /*--------------------------------------------------------------- * WrapperListener Methods *-------------------------------------------------------------*/ /** * The start method is called when the WrapperManager is signaled by the * native wrapper code that it can start its application. This * method call is expected to return, so a new thread should be launched * if necessary. * * @param args List of arguments used to initialize the application. * * @return Any error code if the application should exit on completion * of the start method. If there were no problems then this * method should return null. */ public Integer start(String[] args) { System.out.println("SANDEEP: MyWrapperListener.start()"); try { new java.util.Timer().schedule( new MyTimerTask(args) ,5000); //new Thread(new TCPListener(args),"TCPListener").start(); System.out.println("SANDEEP: Timer to start MyTimerTask scheduled."); } catch(Exception e) { System.out.println("SANDEEP: Exception caught while running MyTimerTask: " + e); return new Integer(-1); } return null; } /** * Called when the application is shutting down. The Wrapper assumes that * this method will return fairly quickly. If the shutdown code code * could potentially take a long time, then WrapperManager.stopping() * should be called to extend the timeout period. If for some reason, * the stop method can not return, then it must call * WrapperManager.stopped() to avoid warning messages from the Wrapper. * * @param exitCode The suggested exit code that will be returned to the OS * when the JVM exits. * * @return The exit code to actually return to the OS. In most cases, this * should just be the value of exitCode, however the user code has * the option of changing the exit code if there are any problems * during shutdown. */ public int stop(int exitCode) { System.out.println("SANDEEP: MyWrapperListener.stop() called with exit code = " + exitCode); // m_app.stop(); return exitCode; } /** * Called whenever the native wrapper code traps a system control signal * against the Java process. It is up to the callback to take any actions * necessary. Possible values are: WrapperManager.WRAPPER_CTRL_C_EVENT, * WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT, or * WRAPPER_CTRL_SHUTDOWN_EVENT * * @param event The system control signal. */ public void controlEvent(int event) { System.out.println("SANDEEP: MyWrapperListener caught control event: " + event); if (WrapperManager.isControlledByNativeWrapper()) { // The Wrapper will take care of this event } else { // We are not being controlled by the Wrapper, so // handle the event ourselves. if ( (event == WrapperManager.WRAPPER_CTRL_C_EVENT) || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) { WrapperManager.stop(0); } } } /*--------------------------------------------------------------- * Main Method *-------------------------------------------------------------*/ public static void main(String[] args) { // Start the application. If the JVM was launched from the native // Wrapper then the application will wait for the native Wrapper to // call the application's start method. Otherwise the start method // will be called immediately. System.out.println("SANDEEP: WrapperListener starting the application..."); WrapperManager.start(new MyWrapperListener(), args); } class MyTimerTask extends java.util.TimerTask { String[] args; MyTimerTask(String[] args){ this.args = args; } public void run() { new MyApp(args); } } } -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< MyApp.java ========== import java.util.*; import org.tanukisoftware.wrapper.WrapperManager; public class MyApp { MyApp(String[] args) { new Timer().schedule(new TimerTask(){ public void run() { System.out.println ("SANDEEP: MyApp started."); System.out.println ("SANDEEP: Exiting with code 1067"); WrapperManager.stop (1067); //System.exit(1067); } } , 10000); } public static void main(String[] args) { new MyApp(args); } } -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< -- 0>< ----- Original Message ----- From: Leif Mortenson <le...@ta...> Date: Thursday, January 8, 2004 7:53 pm Subject: Re: [Wrapper-user] Java service - windows service recovery? > Sandeep, > Sorry, but the Wrapper does not currently exit with the > correct exit > code. I added > a feature request for this last month and try to get it into the > Wrapper > for a near future > version. You might want to monitor the feature request so you > will get > notifications > on its progress. > http://sourceforge.net/tracker/index.php? func=detail&aid=852491&group_id=39428&atid=425190 > > One alternative for you would be to write a simple utility > class > which you specify > as the main class (Ie the first parameter to WrapperSimpleApp) > It > would start by > calling the WrapperManager.getJVMId() method to find out which > invocation number > the JVM was. If it is < 4 then call you real application's main > method. Otherwise > call a method that executes SendMail and then calls System.exit(). > > Alternatively you > could make use of the Java Mail API rather than using SendMail. > It is > quite easy to > use. > > I am also working on another feature that will allow you to > run > arbitrary external > programs in response to various events in the Wrapper life cycles. > Some > users have > needed this functionality so they could, for example, run an > application > after a JVM > crashes, but before a new one is launched. I was planning to have > events for the > startup and shutdown of the Wrapper as well. This feature is > still in > the design phase > so if you have any requirements you would like me to consider, go > ahead > and post them. > http://sourceforge.net/tracker/index.php? func=detail&aid=837037&group_id=39428&atid=425190 > > Cheers, > Leif > > Sandeep Khanna wrote: > > >Hi All, > > > >We have been using Java Service Wrapper for the past several > months to > >run a couple of Java programs as Windows services. > > > >Our current requirement needs us to use the Windows "service recovery > >options". In the Properties page of a service one can set 3 different > >actions to take when a service fails to start for 3 consecutive > times.>We needed this to be able to execute a restart the first 2 > failures and > >execute a command-line SendMail.exe to send mail to support on > the 3rd > >failure. > > > >Unfortunately, my investigation has revealed that the Java Service > >Wrapper does not return an exit code to the Windows Service > manager to > >trigger the service recovery settings. I even tried using the 3 > >integration technique as mentioned on the website, but to no success! > > > >Can somebody comment if this is possible using Java Service > Wrapper and > >it's current feature set and/or I am missing something here? > > > >If YES, please explain how? > >If NO, please suggest alternatives? > > > >Thanks in advance, > >Sandeep Khanna > > > > > > > > |