3 Replies Latest reply on Jun 24, 2014 5:42 AM by Nagarjuna Appasamudram

    Uisng Twiddle in the cron job

    youareapkman youareapkman Newbie

      Hi all,

      I don’t know if the questions of Twiddle should be posted in this forum. Please kindly inform me if I posted in the incorrect forum.

      My problem is about using twiddle in the cron job. When testing the following command in the command line, it runs successfully.

      [root@host]$ /u01/app/jboss/bin/twiddle.sh --server=jnp://server.name:1199 get "jboss.system:service=ThreadPool" "QueueSize"
      QueueSize=0


      But when I run the same command in the cron job, it gives me the following error:

      12:34:02,355 ERROR [Twiddle] Exec failed
      org.jboss.util.NestedRuntimeException: Can't find property: java.naming.factory.initial; - nested throwable: (javax.naming.NoInitialContextException: Can't find property: java.naming.factory.initial)
       at org.jboss.console.twiddle.Twiddle$1.getServer() (Unknown Source)
       at org.jboss.console.twiddle.command.MBeanServerCommand.getMBeanServer() (Unknown Source)
       at org.jboss.console.twiddle.command.GetCommand.execute(java.lang.String[]) (Unknown Source)
       at org.jboss.console.twiddle.Twiddle.main(java.lang.String[]) (Unknown Source)
      Caused by: javax.naming.NoInitialContextException: Can't find property: java.naming.factory.initial
       at javax.naming.spi.NamingManager.getInitialContext(java.util.Hashtable) (/usr/lib64/libgcj.so.5.0.0)
       at javax.naming.InitialContext.getDefaultInitCtx() (/usr/lib64/libgcj.so.5.0.0)
       at javax.naming.InitialContext.getURLOrDefaultInitCtx(java.lang.String) (/usr/lib64/libgcj.so.5.0.0)
       at javax.naming.InitialContext.lookup(java.lang.String) (/usr/lib64/libgcj.so.5.0.0)
       at org.jboss.console.twiddle.Twiddle.createMBeanServerConnection() (Unknown Source)
       at org.jboss.console.twiddle.Twiddle.connect() (Unknown Source)
       at org.jboss.console.twiddle.Twiddle.access$300(org.jboss.console.twiddle.Twiddle) (Unknown Source)
       at org.jboss.console.twiddle.Twiddle$1.getServer() (Unknown Source)
       ...3 more
      

      I know that the cron job will run in a totally different environment than the environment the user logged into the shell, so is this issue due to the environmental variables of the Java and JBoss? I have already correctly set the JAVA_HOME, PATH environmental variables inside the script. What other environmental variables that I need to set when using the twiddle in the cron job environment.

      Regards


        • 1. Re: Uisng Twiddle in the cron job
          Peter Johnson Master

          Based on this: /usr/lib64/libgcj.so.5.0.0, it would appear that you do not have JAVA_HOME set properly because (I think) this shared object is for the GNU Java environment. I suggest you make a copy of twiddle.sh as crontiwwdle,sh, and set your environment in crontwiddle.sh, making sure you set JAVA_HOME to a Sun JDK.

          • 2. Re: Uisng Twiddle in the cron job
            Nagarjuna Appasamudram Newbie

            Hi Peter,

            i schceduled a cron job which uses twiddle.sh to start/stop life cycle of MBean on JBoss. while running the the command from user command line it's executing fine but when it's run by cron job fails with following exception.

             

            08:30:04,098 ERROR [Twiddle] Exec failed
            java.lang.IllegalStateException: Failed to find method for hash:-1860213629447841238 available={4641602872602518031=public abstract javax.management.AttributeList javax.management.MBeanServerConnection.setAttributes(javax.management.ObjectName,javax.management.AttributeList) throws javax.management.InstanceNotFoundException,javax.management.ReflectionException,java.io.IOException, -7543162285726219601=public abstract java.lang.Object javax.management.MBeanServerConnection.getAttribute(javax.management.ObjectName,java.lang.String) throws javax.management.MBeanException,javax.management.AttributeNotFoundException,javax.management.InstanceNotFoundException,javax.management.ReflectionException,java.io.IOException, 5562118711738140267=public abstract void javax.management.MBeanServerConnection.removeNotificationListener(javax.management.ObjectName,javax.management.ObjectName) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.io.IOException, -7359817957176322969=public abstract javax.management.ObjectInstance javax.management.MBeanServerConnection.createMBean(java.lang.String,javax.management.ObjectName) throws javax.management.ReflectionException,javax.management.InstanceAlreadyExistsException,javax.management.MBeanRegistrationException,javax.management.MBeanException,javax.management.NotCompliantMBeanException,java.io.IOException, 6526816259475932921=public abstract void org.jboss.jmx.adaptor.rmi.RMIAdaptor.addNotificationListener(javax.management.ObjectName,org.jboss.jmx.adaptor.rmi.RMINotificationListener,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,java.rmi.RemoteException, 5218389983608935213=public abstract void javax.management.MBeanServerConnection.removeNotificationListener(javax.management.ObjectName,javax.management.NotificationListener) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.io.IOException, 7723756273115807002=public abstract javax.management.AttributeList javax.management.MBeanServerConnection.getAttributes(javax.management.ObjectName,java.lang.String[]) throws javax.management.InstanceNotFoundException,javax.management.ReflectionException,java.io.IOException, -7207158202307939635=public abstract boolean javax.management.MBeanServerConnection.isInstanceOf(javax.management.ObjectName,java.lang.String) throws javax.management.InstanceNotFoundException,java.io.IOException, -3596840071582485950=public abstract void javax.management.MBeanServerConnection.removeNotificationListener(javax.management.ObjectName,javax.management.ObjectName,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.io.IOException, -4921447353789697345=public abstract java.lang.String javax.management.MBeanServerConnection.getDefaultDomain() throws java.io.IOException, -8986071640966670090=public abstract javax.management.ObjectInstance javax.management.MBeanServerConnection.createMBean(java.lang.String,javax.management.ObjectName,javax.management.ObjectName) throws javax.management.ReflectionException,javax.management.InstanceAlreadyExistsException,javax.management.MBeanRegistrationException,javax.management.MBeanException,javax.management.NotCompliantMBeanException,javax.management.InstanceNotFoundException,java.io.IOException, -5126721442700661145=public abstract void javax.management.MBeanServerConnection.addNotificationListener(javax.management.ObjectName,javax.management.ObjectName,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,java.io.IOException, 544126518230447214=public abstract void javax.management.MBeanServerConnection.unregisterMBean(javax.management.ObjectName) throws javax.management.InstanceNotFoundException,javax.management.MBeanRegistrationException,java.io.IOException, 7506667551428032035=public abstract boolean javax.management.MBeanServerConnection.isRegistered(javax.management.ObjectName) throws java.io.IOException, -6810073532948150491=public abstract javax.management.ObjectInstance javax.management.MBeanServerConnection.createMBean(java.lang.String,javax.management.ObjectName,java.lang.Object[],java.lang.String[]) throws javax.management.ReflectionException,javax.management.InstanceAlreadyExistsException,javax.management.MBeanRegistrationException,javax.management.MBeanException,javax.management.NotCompliantMBeanException,java.io.IOException, -5700271068464137991=public abstract javax.management.ObjectInstance javax.management.MBeanServerConnection.createMBean(java.lang.String,javax.management.ObjectName,javax.management.ObjectName,java.lang.Object[],java.lang.String[]) throws javax.management.ReflectionException,javax.management.InstanceAlreadyExistsException,javax.management.MBeanRegistrationException,javax.management.MBeanException,javax.management.NotCompliantMBeanException,javax.management.InstanceNotFoundException,java.io.IOException, 9144349895661963658=public abstract java.lang.String[] javax.management.MBeanServerConnection.getDomains() throws java.io.IOException, 454365017907931965=public abstract void org.jboss.jmx.adaptor.rmi.RMIAdaptorExt.removeNotificationListener(javax.management.ObjectName,org.jboss.jmx.adaptor.rmi.RMINotificationListener) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.rmi.RemoteException, -5710715974500752103=public abstract void org.jboss.jmx.adaptor.rmi.RMIAdaptorExt.addNotificationListener(javax.management.ObjectName,org.jboss.jmx.adaptor.rmi.RMINotificationListener,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,java.rmi.RemoteException, -4410149464935536006=public abstract void javax.management.MBeanServerConnection.setAttribute(javax.management.ObjectName,javax.management.Attribute) throws javax.management.InstanceNotFoundException,javax.management.AttributeNotFoundException,javax.management.InvalidAttributeValueException,javax.management.MBeanException,javax.management.ReflectionException,java.io.IOException, -368468378620489772=public abstract void javax.management.MBeanServerConnection.addNotificationListener(javax.management.ObjectName,javax.management.NotificationListener,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,java.io.IOException, 2444868993596174203=public abstract void org.jboss.jmx.adaptor.rmi.RMIAdaptor.removeNotificationListener(javax.management.ObjectName,org.jboss.jmx.adaptor.rmi.RMINotificationListener) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.rmi.RemoteException, 8688737015066284935=public abstract java.lang.Object javax.management.MBeanServerConnection.invoke(javax.management.ObjectName,java.lang.String,java.lang.Object[],java.lang.String[]) throws javax.management.InstanceNotFoundException,javax.management.MBeanException,javax.management.ReflectionException,java.io.IOException, -4883798046778604448=public abstract java.lang.Integer javax.management.MBeanServerConnection.getMBeanCount() throws java.io.IOException, 2869574989893044843=public abstract javax.management.ObjectInstance javax.management.MBeanServerConnection.getObjectInstance(javax.management.ObjectName) throws javax.management.InstanceNotFoundException,java.io.IOException, 3851446659803776630=public abstract void javax.management.MBeanServerConnection.removeNotificationListener(javax.management.ObjectName,javax.management.NotificationListener,javax.management.NotificationFilter,java.lang.Object) throws javax.management.InstanceNotFoundException,javax.management.ListenerNotFoundException,java.io.IOException, 3268627599836747539=public abstract java.util.Set javax.management.MBeanServerConnection.queryMBeans(javax.management.ObjectName,javax.management.QueryExp) throws java.io.IOException, -4975332070162614141=public abstract javax.management.MBeanInfo javax.management.MBeanServerConnection.getMBeanInfo(javax.management.ObjectName) throws javax.management.InstanceNotFoundException,javax.management.IntrospectionException,javax.management.ReflectionException,java.io.IOException, 4572179916322875317=public abstract java.util.Set javax.management.MBeanServerConnection.queryNames(javax.management.ObjectName,javax.management.QueryExp) throws java.io.IOException}
               at org.jboss.invocation.MarshalledInvocation.getMethod(MarshalledInvocation.java:407)
               at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:232)
               at sun.reflect.GeneratedMethodAccessor339.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:606)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
               at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:138)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)
               at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:140)
               at org.jboss.jmx.connector.invoker.SerializableInterceptor.invoke(SerializableInterceptor.java:74)
               at org.jboss.jmx.connector.invoker.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:107)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
               at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:180)
               at sun.reflect.GeneratedMethodAccessor338.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:606)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
               at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:855)
               at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:422)
               at sun.reflect.GeneratedMethodAccessor337.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:606)
               at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
               at sun.rmi.transport.Transport$1.run(Transport.java:177)
               at sun.rmi.transport.Transport$1.run(Transport.java:174)
               at java.security.AccessController.doPrivileged(AccessController.java)
               at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
               at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
               at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
               at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
               at java.lang.Thread.run(Thread.java:724)

             

            ================================================

             

            please let me know any environment variable or any settings/changes need to be done, to make it executable in cron job.

             

            Regards,

            Nagarjuna

            • 3. Re: Uisng Twiddle in the cron job
              Nagarjuna Appasamudram Newbie

              Hi,

              i found the problem. refer: http://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work

               

              cron is passing minimum set of environmental variables. like as below

               

              * * * * *  env > /tmp/env.oupt

               

              The above cron runs and below are the set of environmental variables cron is giving to jobs.

              =*3248*/bin/env

              HOME=/opt/jboss/stage

              LOGNAME=jbossstg

              PATH=/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin

              PWD=/opt/jboss/stage

              SHELL=/bin/ksh

              SHLVL=1

              USER=jboss

               

              The PATH variable doesn't include all as user jboss had.

              like jboss has PATH=/opt/java/jdk/bin:/opt/jboss/stage/tools/apache-ant-1.8.1/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/jboss/stage/bin

               

              i copied the above PATH into my script and Cron job is working fine now.