|
From: Leif M. <lei...@ta...> - 2012-02-08 18:49:24
|
Fabio, By default, the Wrapper dos not view and exit -1 as a failure. That is a valid way of the JVM exiting. If you wish to restart or take some other action based on a particular exit code, you can use the wrapper.on_exit.N properties: http://wrapper.tanukisoftware.com/doc/english/prop-on-exit-n.html For example: wrapper.on_exit.default=RESTART wrapper.on_exit.0=SHUTDOWN That will restart for any exit code other than 0. Cheers, Leif 2012/2/9 Fábio Braga de Oliveira <gtc...@cf...>: > Hello Leif, thank you for your fast response. > > I´m trying to emulate a application failure, I´m using the following class: > > import org.apache.log4j.Logger; > import org.tanukisoftware.wrapper.WrapperListener; > import org.tanukisoftware.wrapper.WrapperManager; > > public class Runner implements WrapperListener { > > private static Logger LOG = Logger.getLogger(Runner.class); > > private Runner runner; > > /** > * @param args > * @return > * @throws InterruptedException > * @throws Exception > */ > public Integer start(String[] args) { > if (runner == null) { > runner = this; > } > runner.start(); > > return null; > > } > > public static void main(String args[]) throws InterruptedException { > WrapperManager.start(new Runner(), args); > } > > public void start() { > LOG.info("Starting a Java-Window Service test"); > > Runnable r = new Runnable() { > > @Override > public void run() { > try { > Thread.sleep(10000); > > LOG.warn("The app will emulate a failure in 50s"); > > Thread.sleep(30000); > LOG.warn("The app will emulate a failure in 20s"); > > Thread.sleep(10000); > LOG.warn("The app will emulate a failure in 10s"); > > Thread.sleep(10000); > LOG.fatal("Emulating a app failure!"); > > System.exit(-1); > } catch (InterruptedException e) { > throw new RuntimeException(e); > } > } > }; > new Thread(r).start(); > } > > @Override > public void controlEvent(int arg0) { > // TODO Auto-generated method stub > > } > > @Override > public int stop(int exitCode) { > LOG.info("App exit code: " + exitCode); > return exitCode; > } > > } > > > How you can see, I´m using the WrapperListener, I started a thread which > count down until exit with a System.exit(-1). The classpath contain the > wrapper.jar, the log4j-1.2.16.jar and my app jar, I´m using the > NTEventLogAppender, and I can see the log messages being writed to the Event > Log, but the service after 60s die and don´t come back after 1min as > configured. > > > This information is useful? > > > On Wed, Feb 8, 2012 at 3:42 PM, Leif Mortenson > <lei...@ta...> wrote: >> >> Fabio, >> Thank you for the configuration file. It looks like you have it set >> up correctly. There are a couple things to keep in mind. >> >> 1) There are two components which are being monitored. >> >> a) The first is the JVM itself. Many JVM problems can be monitored, >> detected, and recovered by the Wrapper process. In these cases, the >> wrapper.ntservice.recovery.* properties are not used. >> >> b) The second is if the Wrapper process itself crashes. This is rare, >> but if it did happen, then the Windows Service Manager can make use of >> the settings in the wrapper.ntservice.recovery.* properties to restart >> the Wrapper process as a service and thus make sure your service stays >> up and running. >> >> 2) The wrapper.ntservice.recovery.* properties are available in the >> Standard and Professional editions. >> wrapper.tanukisoftware.com/doc/english/prop-ntservice-recovery.html >> >> How are you running your tests? Is it a test of the JVM crashing or >> the Wrapper? >> >> Cheers, >> Leif >> >> 2012/2/9 Fábio Braga de Oliveira <gtc...@cf...>: >> > Hello list! >> > >> > I´m trying to put my java application to run as a Windows Service, and I >> > would like to make this service very fail safe. For this, I´m evaluation >> > the >> > Java Service Wrapper, and trying to configure the Windows to restart the >> > service if it fails (using the recovery tab in the service >> > configurations), >> > but without success. >> > >> > My question is: What are the requirements/parameters to achieve this >> > requirement? I already tryied the integration methods 1 and 3, but for >> > now I >> > don´t now what´s the right return code to force a automatic restart. >> > >> > My wrapper.conf is attached. >> > >> > Thank you in advance for any help! |