9 Replies Latest reply on Nov 16, 2011 6:44 PM by Tsz Lam

    Running JBoss as windows service with procrun

    Thomas W Newbie

      I have been experimenting with procrun (http://commons.apache.org/daemon/procrun.html) to make JBoss (4.x and 5.x) run as service. All works fine as long as the JVM is launched as a separate process (java or exe mode). When using the jvm (jvm.dll) mode however, JBoss fails to start with class loading related problems. Using the -verbose option I can see that classes are loaded differently between these execution modes.

      This problem does not occur with Tomcat (it uses procrun with the windows service installer).

      Has anyone managed to run JBoss with procrun or through JNI/jvm.dll?

      I would prefer this mode as it does not spawn another java process and shows the process under the procrun executable name in the process list rather than one of potentially many java processes.

      Thanks!


        • 1. Re: Running JBoss as windows service with procrun
          Peter Johnson Master

          I haven't used procrun (JBoss AS 5.1 comes with the necessary files to run it as a service (well, supposedly 5.0.x also comes with those files but they are broke)). For loading the jvm.dll directly, have you specified to correct JVM option? Did you examine the exact command line options passed to java.exe within run.bat? And are you configuring those exact same options for runproc?

          • 2. Re: Running JBoss as windows service with procrun
            Thomas W Newbie

            Yes, I'm able to launch JBoss through procrun when using the standalone java mode with the options that are otherwise produced by run.bat. But when switching to the jvm.dll mode, these same options yield different behavior and JBoss fails to load.

            The two advantages I see for using procrun are:

            (1) Service manager with icon in system tray to configure/stop/start.
            (2) Distinct process name in task manager (when launched through jvm.dll).

            Is there any other wrapper available that provides the same and is known to work with JBoss?

            • 3. Re: Running JBoss as windows service with procrun
              Peter Johnson Master

              I think that JavaSevice (http://javaservice.objectweb.org/) loads the JVM directly, but it has fallen out of favor: http://www.jboss.org/community/wiki/RunJBossAsAServiceOnWindows

              Here is one more thing you can try. Set _JAVA_LAUNCHER_DEBUG and run run.bat. This option causes java.exe to print out, among other things, the exact parameters passed to the JVM.

              If that doesn't help you, then could you provide details on how you configured procrun?

              One other thought - to meet objective 2, you could always copy java.exe as jboss.exe and change run.bat to use jboss.exe. I've done something similar before.

              • 5. Re: Running JBoss as windows service with procrun
                Thomas W Newbie

                Yes, copying java.exe would be the method of last resort, if nothing else helps.

                So far I know that the JBoss startup via org.jboss.Main shows a different class loading behavior, depending on whether it is runs through java.exe or procrun.

                Using my own main class and jconsole I have verified that the JVM arguments are identical in both cases and so are the system properties.

                I get the _JAVA_LAUNCHER_DEBUG output only through java.exe, so I would assume it is produced by the launcher and not by jvm.dll?

                Here are the procrun commands to register the service for either case:

                set JBOSS_DIR=c:\JBoss5
                set JAVA_HOME="C:\Program Files (x86)\Java\jdk1.6.0_12"
                
                rem delete existing service
                "%JBOSS_DIR%\bin\jboss5.exe" //DS//jboss5
                
                rem register service
                "%JBOSS_DIR%\bin\jboss5.exe" //IS//jboss5 --DisplayName "jboss5" --Description "jboss5 service test" --LogPath "%JBOSS_DIR%\server\default\log" --Install "%JBOSS_DIR%\bin\jboss5.exe" --Jvm %JAVA_HOME%\jre\bin\server\jvm.dll --StartPath "%JBOSS_DIR%" --StopPath "%JBOSS_DIR%" --StdOutput auto --StdError auto
                rem jvm.dll mode
                "%JBOSS_DIR%\bin\jboss5.exe" //US//jboss5 --Classpath "%JBOSS_DIR%\bin\run.jar" --StartClass org.jboss.Main --StopClass org.jboss.Shutdown --StartParams "-c#default#-b#0.0.0.0" --StopParams TBD --StartMode jvm --StopMode jvm
                "%JBOSS_DIR%\bin\jboss5.exe" //US//jboss5 --JvmOptions "-Dprogram.name=run.bat#-Xms128m#-Xmx512m#-XX:MaxPermSize=256m#-Dorg.jboss.resolver.warning=true#-Dsun.rmi.dgc.client.gcInterval=3600000#-Dsun.rmi.dgc.server.gcInterval=3600000#-Djboss.platform.mbeanserver#-Djava.endorsed.dirs=%JBOSS_DIR%\lib\endorsed#-Djava.class.path=%JBOSS_DIR%\bin\run.jar#-Dsun.java.command=org.jboss.Main#-Dsun.java.launcher=SUN_STANDARD"
                rem java.exe mode
                rem "%JBOSS_DIR%\bin\jboss5.exe" //US//jboss5 --StartParams "-Dprogram.name=run.bat#-Xms128m#-Xmx512m#-XX:MaxPermSize=256m#-Dorg.jboss.resolver.warning=true#-Dsun.rmi.dgc.client.gcInterval=3600000#-Dsun.rmi.dgc.server.gcInterval=3600000#-Djboss.platform.mbeanserver#-Djava.endorsed.dirs=%JBOSS_DIR%\lib\endorsed#-Djava.class.path=%JBOSS_DIR%\bin\run.jar#-Dsun.java.command=org.jboss.Main#-Dsun.java.launcher=SUN_STANDARD#org.jboss.Main#-c#default#-b#0.0.0.0" --StopParams TBD --StartImage=%JAVA_HOME%\bin\java.exe --StopImage=%JAVA_HOME%\bin\java.exe --StartMode exe --StopMode exe
                



                • 6. Re: Running JBoss as windows service with procrun
                  Thomas W Newbie

                  And here is the error for JBoss5:

                  Failed to boot JBoss:
                  java.lang.ClassCastException: org.jboss.bootstrap.microcontainer.ServerImpl cannot be cast to org.jboss.bootstrap.spi.Server
                   at org.jboss.system.server.ServerLoader.createServer(ServerLoader.java:358)
                   at org.jboss.system.server.ServerLoader.load(ServerLoader.java:332)
                   at org.jboss.Main.boot(Main.java:203)
                   at org.jboss.Main$1.run(Main.java:547)
                   at java.lang.Thread.run(Thread.java:619)
                  



                  procrun/jvm.dll loads org.jboss.bootstrap.spi.Server first from bootstrap.jar and later again from run.jar, with java.exe it loads only from run.jar

                  [2009-07-20 14:35:42] [info] [Loaded org.jboss.system.NoAnnotationURLClassLoader from file:/C:/JBoss5/bin/run.jar]
                  [2009-07-20 14:35:42] [info] [Loaded org.jboss.bootstrap.spi.Server from file:/C:/JBoss5/lib/jboss-bootstrap.jar]
                  




                  • 7. Re: Running JBoss as windows service with procrun
                    Thomas W Newbie

                    There are two integration issues between procrun and JBoss bootstrap process after further investigation:

                    1) With procrun launcher, the initial context class loader is null, causing JBoss to set a null parent class loader on its URL bootstrap class loader - this explains why subsequently classes from run.jar are not visible within the bootstrap process. Setting the context class loader to the class loader of org.jboss.Main when it is null solves this problem. This is the setup found when running through java.exe

                    2) Termination of the main thread (which does nothing but spawning the bootstrap thread) causes the JVM to exit with procrun while the bootstrap thread is loading the server. With java.exe, termination of the main thread does not have any effect, the JVM will continue to run.

                    Does anybody have insight into or any info regarding these two issues and what the best fix would be?

                    • 8. Re: Running JBoss as windows service with procrun
                      Peter Johnson Master

                      #2 sounds like a defect in procrun - I don't think that JVM launchers are supposed to exit until all threads exit. Have you looked to see if there is some procrun option related to this?

                      • 9. Re: Running JBoss as windows service with procrun
                        Tsz Lam Newbie

                        Even though it is silly to resurrect this thread, I think it will be helpful for people who also end up here without a clue.

                         

                        For #2: Since JBoss has a shutdown hook installed to do the clean-up, we can make use of System.exit(0) to invoke it.

                        --StopMode=jvm --StopPath=%WORKING_DIR% --StopClass=java.lang.System --StopMethod=exit --StopParams=1 --StopTimeout=45

                         

                        Here is my entire script for installing my JBoss 64-bit Windows Service

                        * I assume that both environment variables (JAVA_HOME & JBOSS_HOME) are well defined.

                         

                        {code}

                        set DAEMON_DIR=C:/jboss/commons-daemon-1.0.7/windows

                        set DAEMON_IMG=%DAEMON_DIR%/amd64/prunsrv.exe

                         

                        set JAVA_HOME=C:/Java/64bit/jdk1.6.0_27

                        set Jvm=%JAVA_HOME%/jre/bin/server/jvm.dll

                         

                        set NAME=jbossserverservice

                        set DISPLAY="JBoss Server"

                        set WORKING_DIR=%JBOSS_HOME%/bin

                         

                        rem =================================JBoss Runtime Configuration ===================================

                        set JAVA=%JAVA_HOME%\bin\java

                        set JAVAC_JAR=%JAVA_HOME%\lib\tools.jar

                         

                        set XMS=1024

                        set XMX=3096

                         

                        set VM_OPTS=-XX:+UseCompressedOops

                         

                        rem --- JVM memory non-heap allocation pool parameters. Modify as appropriate. ---

                        set VM_OPTS=%VM_OPTS%;-XX:PermSize=64m;-XX:MaxPermSize=128m

                         

                        rem With Sun JVMs reduce the RMI GCs to once per hour

                        set VM_OPTS=%VM_OPTS%;-Dsun.rmi.dgc.client.gcInterval=3600000;-Dsun.rmi.dgc.server.gcInterval=3600000

                         

                        rem --- Enable the jconsole agent locally with integration of the jboss MBeans ---

                        set VM_OPTS=%VM_OPTS%;-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl

                        set VM_OPTS=%VM_OPTS%;-Djboss.platform.mbeanserver

                        set VM_OPTS=%VM_OPTS%;-Dcom.sun.management.jmxremote

                         

                        rem --- JPDA options. Uncomment and modify as appropriate to enable remote debugging. ---

                        rem set VM_OPTS=-Xdebug;-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n;%VM_OPTS%

                         

                        rem --- Setup the java endorsed dirs ---

                        set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed

                        set VM_OPTS=%VM_OPTS%;-Djava.endorsed.dirs=%JBOSS_ENDORSED_DIRS%

                         

                        rem --- Find run.jar, or we can't continue ---

                        set RUN_JAR=%JBOSS_HOME%\bin\run.jar

                        rem !!! set STOP_MAIN=org.jboss.Shutdown

                        rem !!! set STOP_JAR=%JBOSS_HOME%\bin\shutdown.jar

                        rem !!! set STOP_LIB=%STOP_JAR%;%JBOSS_HOME%/client/jbossall-client.jar

                        rem !!! set STOP_MAIN=org.jboss.Shutdown

                        rem !!! set STOP_PARAM=

                         

                        rem =================================================================================================

                         

                        set LIB=%JAVAC_JAR%;%RUN_JAR%

                        set START_MAIN=org.jboss.Main

                        set START_PARAM=

                         

                         

                        set LogPath=%JBOSS_HOME%/server/default/log/

                        set LogPrefix=service

                         

                        rem --- Shut down JBoss System with System.exit(0), so JBoss build-in ShutDownHook will have a chance to do some clean up before exit. (Time-out in 45 seconds)

                        set SHUT_DOWN_HOOK=--StopMode=jvm --StopPath=%WORKING_DIR% --StopClass=java.lang.System --StopMethod=exit --StopParams=1 --StopTimeout=45

                         

                        %DAEMON_DIR%/prunsrv //IS/JBossServer --DisplayName=%NAME% --Description=%DISPLAY% --Install=%DAEMON_IMG% --Jvm=%Jvm% --JvmMs=%XMS% --JvmMx=%XMX% --JvmOptions=%VM_OPTS% --Classpath=%LIB% --StartMode=jvm --StartPath=%WORKING_DIR% --StartClass=%START_MAIN% --StartParams=%START_PARAM% %SHUT_DOWN_HOOK% --Startup=auto --LogLevel=DEBUG --LogPath=%LogPath% --LogPrefix=%LogPrefix%

                        {code}