6 Replies Latest reply on Apr 15, 2008 3:26 PM by thoste

    How can I find out from command line if JBoss is currently r

    thoste Newbie

      I want to find out from command line (=NOT by investigating running programs e.g. TaskManager under WinXP) if JBoss is crrently running.

      The check should be performed from a batch script and should return a true or false answer.

      So I am searching something like this:

      checkifjbossrunning.bat:

      java org.JBoss.Main -areyourrunning
      if %errorlevel%==1 (Echo JBoss is running) else ( Echo JBoss is not running)


      Is this somehow possible?
      Thomas

        • 1. Re: How can I find out from command line if JBoss is current
          Peter Johnson Master

          You could run a twiddle command to check the value of an attribute of an mbean, such as:

          twiddle get "jboss.system:type=Server" Started

          This is not a perfect solution because this command will yield "Started=true" as soon as JMX and JNDI are running, but HTTP and thus web applications are usually not available until a few seconds later.

          • 2. Re: How can I find out from command line if JBoss is current
            thoste Newbie

             

            "PeterJ" wrote:
            You could run a twiddle command to check the value of an attribute of an mbean, such as:

            twiddle get "jboss.system:type=Server" Started

            This is not a perfect solution because this command will yield "Started=true" as soon as JMX and JNDI are running, but HTTP and thus web applications are usually not available until a few seconds later.


            Your suggestion implies that if JBoss is not running the above command returns a statement

            Started=false

            But this is not the case. Instead I am getting an exception (see below).

            Is there another solution?

            D:\JBoss\v4\bin>twiddle get "jboss.system:type=Server" Started
            11:49:28,781 ERROR [Twiddle] Exec failed
            org.jboss.util.NestedRuntimeException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming
            at org.jboss.console.twiddle.Twiddle$1.getServer(Twiddle.java:143)
            at org.jboss.console.twiddle.command.MBeanServerCommand.getMBeanServer(MBeanServerCommand.java:59)
            at org.jboss.console.twiddle.command.GetCommand.execute(GetCommand.java:149)
            at org.jboss.console.twiddle.Twiddle.main(Twiddle.java:305)
            Caused by: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: jav
            at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at org.jboss.console.twiddle.Twiddle.createMBeanServerConnection(Twiddle.java:250)
            at org.jboss.console.twiddle.Twiddle.connect(Twiddle.java:268)
            at org.jboss.console.twiddle.Twiddle.access$300(Twiddle.java:62)
            at org.jboss.console.twiddle.Twiddle$1.getServer(Twiddle.java:139)
            ... 3 more
            Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableExceptio
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
            at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
            ... 10 more
            Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connect
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
            ... 11 more
            Caused by: java.net.ConnectException: Connection refused: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
            at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
            at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
            at java.net.Socket.connect(Socket.java:507)
            at java.net.Socket.connect(Socket.java:457)
            at java.net.Socket.(Socket.java:365)
            at java.net.Socket.(Socket.java:265)
            at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84)
            at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77)
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)
            ... 11 more
            D:\JBoss\v4\bin>



            • 3. Re: How can I find out from command line if JBoss is current
              Peter Johnson Master

              That is the expected response if the server is not running. Twiddle connects to the jbossas server and queries an bean and returns a response. Thus, if the server is running, you get

              Started=true

              But if jbossas is not running, twiddle cannot connect to the server and thus you get an exception. It is impossible to get "Started=false".

              If yoo need a "yes" or "no" response, you need to wrap twiddle within a script that examines the response and then replies with yes or no.

              My caveat was more about the timing window. In other words, what do you mean by "if JBoss is crrently running"? Here is a hypothetical timeline for starting jbossas:

              1 - not yet running
              2 - you enter run.bat, and java.exe starts
              3 - various services are initialized
              4 - JNDI port is opened and JMX is usable
              5 - more services and applications start up
              6 - ready to accept outside input (e.g. HTTP requests)

              By "jbossas is running", do you mean states 2-6, or just state 6? Either way, the "twiddle" solution yields a incorrect result for a certain period of time. For example, if "jbossas is running" means state 6, them you have a false positive all during states 4 and 5. The question is, can you live with that timing window?

              • 4. Re: How can I find out from command line if JBoss is current
                thoste Newbie

                 

                "PeterJ" wrote:
                The question is, can you live with that timing window?


                Yes, these few seconds delay are ok.

                Do you have another solution for me?

                • 5. Re: How can I find out from command line if JBoss is current
                  Peter Johnson Master

                  No, there is not other solution that I have been able to find. (In one of my apps I had the same problem - I needed to be able to tell if various app servers were running and I used a similar solution with similar caveats; though my apps were web apps.)

                  • 6. Re: How can I find out from command line if JBoss is current
                    thoste Newbie

                     

                    "PeterJ" wrote:
                    No, there is not other solution that I have been able to find. (In one of my apps I had the same problem - I needed to be able to tell if various app servers were running and I used a similar solution with similar caveats; though my apps were web apps.)


                    Isn't that a feature which should be put on the todo list for the next release?
                    It seems to be easy to implement.

                    Thomas