LendKey

Wednesday, April 21, 2010

Run Terracotta Server as Windows Service

Terracotta is a JVM-level Java clustering solution. Lots of Java frameworks and libraries, such as Ehcache, Quartz, Web Session, have been offering clustered version over this nice platform.

This document describes steps to install Terracotta Server as a Windows Service that can be managed and executed just as any other standard Windows services, including auto startup when Windows is started and management through standard service management UI and command.

Setup Procedure


Preparation

1. Download and install JDK
    Goto http://java.sun.com to download JDK 1.6.
    As of now, JDK 1.6.0_u17 is certified and recommended.
    Install JDK to c:\java\jdk_1.6.0_17

2. Download and install Terracotta
    Open source version can be downloaded from http://www.terracotta.org.
    Enterprise commercial version can be downloaded by contacting sales@terracottatech.com.
    If download is in form of tar.gz file, untar it to c:\terracotta, such as c:\terracotta\terracotta-3.2.1_1.
    If download is in jar form, double click the file to start installation. Follow installation steps to install Terracotta to to c:\terracotta, such as c:\terracotta\terracotta-3.2.1_1.

3. If Terracotta License file is needed, copy it to Terracotta Installation Folder, such as \terracotta\terracotta3.2.1_1.

4. Download Windows Resource Kit Tools
    Go to http://www.microsoft.com to search and download Windows Resource Kit Tools that is suitable to the targeted Windows version.
    Run the installer and install it to the default folder.
    Copy anysrv.exe to c:\terracotta\terracotta-3.2.1_1\bin

5. Make sure sc.exe is included in your Windows installation. Otherwise, download it from Microsoft’s website

Configuration

1. Create tc-config.xml to be used by Terracotta Server, place it to bin folder under Terracotta installation home folder.

2. Create Registration file
    Create a text file with any text editor, copy paste the following text into the file and save it as tcservice.reg.

REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Terracotta\Parameters]
"Application"="\"C:\\Java\\jdk1.6.0_17\\bin\\java.exe\\"
"AppParameters"="-cp c:\\terracotta\\terracotta-3.2.1_1\\lib\\tc.jar -server -Xms4G –Xmx4G -XX:+HeapDumpOnOutOfMemoryError -Dtc.install-root=c:\\terracotta\\terracotta-3.2.1_1 com.tc.server.TCServerMain"
"AppDirectory"="c:\\terracotta\\terracotta-3.2.1_1\\"


Note:
If you need to pass more parameters to TC server, yon can do so by appending them to the AppParameters section. For example, if I want to specify a tc-config.xml and a server name, I can change the AppParameters to:
"AppParameters"="-cp c:\\terracotta\\terracotta-3.2.1_1\\lib\\tc.jar -server -Xms4G –Xmx4G -XX:+HeapDumpOnOutOfMemoryError -Dtc.install-root=c:\\terracotta\\terracotta-3.2.1_1 com.tc.server.TCServerMain -f c:\\terracotta\\my-tc-config.xml -n Server1"


Install Service

1. Create Windows Service
    Open a command prompt window as System Administrator.
    Run the following command:
sc.exe create Terracotta binPath= “c:\terracotta\terracotta-3.2.1_1\bin\srvany.exe” type= own start= auto DisplayName= “Terracotta Server 3.2.1_1”
    It will create a new Windows Service named Terracotta which will be started automatically when Windows is started.

2. Modify service parameter, so it will start Terracotta Server
    In the same command prompt box, run:
regedit tcserver.reg
    It will modify the newly created service to run Terracotta Server as a Java application.

Test

1. In Windows Service Management window, start the service. Make sure there’s no error popped up

2. Run dev-console.bat from Terracotta Installation folder and connect to server_name 9520. Developer’s console should be able to login and display the standard Terracotta management interface.

Trouble Shooting

1. Pay attention to quotation signs and garbage characters when copy&paste code snippet from this article


2. To test run the service manually
Since Windows doesn't provide any console based information when starting service, it could be very difficult to trouble shoot problems.
If your service does not start as expected, it is highly recommended to run the service manually just to make sure everything is configured correctly.
To do so, you can follow the following steps:

  1. Open a Commend Shell
  2. Go to folder defined by AppDirectory
  3. Run the Application with AppParameters
In my example, it will be:

CD c:\terracotta\terracotta-3.2.1_1
C:\Java\jdk1.6.0_17\bin\java.exe -cp c:\terracotta\terracotta-3.2.1_1\lib\tc.jar -server -Xms4G –Xmx4G -XX:+HeapDumpOnOutOfMemoryError -Dtc.install-root=c:\terracotta\terracotta-3.2.1_1 com.tc.server.TCServerMain