JBoss and Windows Start Up Services

From Initq

Jump to: navigation, search

Contents

Before you start

This article will be dealing with the windows registry and editing jboss jar files. If you are not comfortable with this then please find another way to achieve this process. We looked and were unable to find any method so we developed our own. This article makes us very happy to be using *nix systems.

JBoss Start UP

This article is meant for people who are running multiple instances of jboss on windows and require a way to start their instance from windows services. Normally we start up jboss from the console but in a case of reboot the jboss service will not start and your application will be down. After reading quite a number of articles on how to achieve this we came up with our own way. You may find other ways of doing this with javaservice or wrappers.

Requirments

You will need to download the following two files. Please copy them in your system32 folder.

File to copy

Let's say your application is called test1. You should have the following ready.

  •  %JBoss_HOME%\server\test1

We are running our test1 apps at port 18080.

  • copy %JBoss_Home%\bin\run.bat to %JBoss_Home%\bin\run_test1.bat.

You can modify run_test1.bat and put in all the environment variables you need for your apps.

  • copy %JBoss_Home%\bin\shutdown.bat to %JBoss_Home%\bin\test1_shutdown.bat.

We normally change jdk versions so we put the following line in our run_test1.bat and test1_shutdown.bat files.

set JAVA_HOME=C:\jdk1.5.0_09
Please make sure you do not put the JAVA_HOME variable under an if statement. Check both files for pause statements, since these will be services now, you will need to comment or remove any pauses.
  • copy %JBoss_Home%\bin\shutdown.jar to %JBoss_Home%\bin\test1_shutdown.jar.

Use 7zip or any other unzip utility and open up test1_shutdown.jar file. Inside the jar file look for a file called jndi.properties.

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
jnp.disableDiscovery=true
Change the 1099 port to your jboss instance port, in our case that will be 11099.
  • Edit test1_shutdown.bat and change
set MAIN_JAR_NAME=shutdown.jar to set MAIN_JAR_NAME=test1_shutdown.jar

Set Up Windows Services

Open up a cmd console and type the following:

INSTSRV test1_start "c:\windows\system32\SRVANY.EXE"
Test1 will be your start up service name.
INSTSRV test1_stop "c:\windows\system32\SRVANY.EXE"

If you make a mistake and wanted to remove the service then do the following:

INSTSRV test1_stop REMOVE

Open up the Registry Editor (Click on the Start Button, select Run, and type REGEDIT)

   * Locate the following key:
     HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[service name]
   * From the Edit menu, select New, select Key, and name the new key Parameters
   * Highlight the Parameters key
   * From the Edit menu, select New, select String Value, and name the new value Application
   * From the Edit menu, select Modify

For test1_start service you will enter:

c:\jboss-4.2.3\bin\run_test1.bat -c test1 -Djboss.bind.address=0.0.0.0

For test1_stop service you will enter:

c:\jboss-4.2.3\bin\test1_shutdown.bat -Dtest1

Close the Registry Editor.

Testing

Go to your services and start the test1_start service. Try to access the jmx-console at port 18080.

Shutting down

To shutdown you will need to first stop the test1_start service. This actually will not stop the application nor jboss on port 18080, but we need to satisfy Window$. To really stop the service you will need to run test1_stop service.

Personal tools