• Bug
  • Status: Open
  • 2 Major
  • Resolution:
  • prodmgmt
  • Reporter: hmak
  • August 26, 2009
  • 0
  • Watchers: 1
  • March 19, 2010

Description

Terracotta server does not run under Apache procrun (http://commons.apache.org/daemon/procrun.html). The problem is that com.tc.server.TCServerMain.main() returns too early, making procrun believe the process is dead. Request that main() block until the server is shut down.

To reproduce:

  1. Install TC server as a Windows service

procrun.exe //IS//VMPTCSERVER –DisplayName=”Terracotta server” –install=procrun.exe –Jvm=%JAVA_HOME%\jre\bin\server\jvm.dll –JvmMs=512 –JvmMx=512 –Classpath=%TC_HOME%\lib\tc.jar –JvmOptions=-XX:+HeapDumpOnOutOfMemoryError;-Dtc.install-root=%TC_HOME% –Startup=auto –StartMode=jvm –StartClass=com.tc.server.TCServerMain –StopMode=java –StopParams=-cp;%TC_HOME%\lib\tc.jar’;com.tc.admin.TCStop; –LogPrefix=win_service.log –LogLevel=DEBUG

  1. Start TC server from Windows Service Control Manager (services.msc)

  2. win_service.log will show JVM created but process will terminate

Expected behavior:

Process should not terminate and should appear as “Started” in services.msc

Comments

Howard Mak 2009-08-26

Email correspondence that led to this particular JIRA

—– Original Message —– From: Nitin

Another option I see at this point is you write a new class to start terracotta server which internally

1) calls TCServerMain.main()
2) Register a shutdown hook
3) Waits in the latch
4) In shutdown hook you decrement the latch and wake your classes mail thread.

—– Original Message —– From: Howard

Can the following patch be applied to

URL: http://svn.terracotta.org/svn/tc/dso/tags/3.0.1/code/base/deploy/src/com/tc/server/TCServerImpl.java
Revision: 13491
Last Changed Rev: 12315

Index: TCServerImpl.java

*** TCServerImpl.java (revision 13491) — TCServerImpl.java (working copy) *************** *** 65,84 **** — 65,85 —- import com.tc.stats.DSOMBean; import com.tc.util.Assert;

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.List;

  • import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue;

    import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.NotCompliantMBeanException;

    public class TCServerImpl extends SEDA implements TCServer {

    public static final String VERSION_SERVLET_PATH = “/version”; *************** *** 204,247 **** — 205,252 —- if (!this.state.isStartState()) { stopServer(); logger.info(“Server stopped.”); } else { logger.warn(“Server in incorrect state (“ + this.state.getState() + “) to be stopped.”); } }

    }

  • private final CountDownLatch m_shutdown = new CountDownLatch(1); + public void start() { synchronized (this.stateLock) { if (this.state.isStartState()) { try { startServer();
  • m_shutdown.await(); } catch (Throwable t) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeException(t); } } else { logger.warn(“Server in incorrect state (“ + this.state.getState() + “) to be started.”); } } }
public boolean canShutdown() {
  return (!this.state.isStartState() || (this.dsoServer != null && this.dsoServer.isBlocking()))
         && !this.state.isStopState();
}

public synchronized void shutdown() {
  if (canShutdown()) {
    this.state.setState(StateManager.STOP_STATE);
    consoleLogger.info("Server exiting..."); +       m\_shutdown.countDown();
    Runtime.getRuntime().exit(0);
  } else {
    logger.warn("Server in incorrect state (" + this.state.getState() + ") to be shutdown.");
  }
}

public long getStartTime() {
  return this.startTime;
}

—–Original Message—– From: Howard

Turns out that the Apache procrun adapter … assumes the service has quit if the TCServerMain.main() method returns. When launched instead from java.exe, the JVM hangs around because of non-daemon threads.

Fiona OShea 2009-08-26

Field to try Richard Wilkinson fix for running as a service

Sreenivasan Iyer 2009-08-27

Yes the mechanism suggested at http://richard-wilkinson.co.uk/2008/07/11/how-to-run-terracotta-as-a-service/ does work. In any case, for right now there is a workaround in play to make it work with Apache Procrun as well. It should be fixed at some point though, correctly.