checking java process

I have the below play to check if JBoss application server is RUNNING. I am getting the message “JBoss Process is running on localhost” (inventory_hostname = localhost) even when JBoss is DOWN. Am I doing anything wrong here?

tasks:

  • name: Check JBOss java process
    shell: ps -ef | grep java | grep “jboss.server”
    register: jboss_java_process
    ignore_errors: false

  • debug: msg=“JBoss Process is running on {{ inventory_hostname }}”
    when: jboss_java_process.stdout.find(“jboss.server”) != -1

-SKR

Try this way:

when: ‘jboss.server’ in jboss_java_process.stdout

tasks:
   - name: Check JBOss java process
     shell: ps -f "jboss.server"
     register: jboss_java_process
     ignore_errors: false

   - debug: msg="JBoss Process is running on {{ inventory_hostname }}"
     when: jboss_java_process.stdout_lines|length > 0

We did it like this:

  • name: Check for previous running Wildfly instances
    shell: ps -ef | grep jboss | grep java | grep -v activemq | grep -v /bin/sh | grep -v grep | awk ‘{print $2}’
    register: ps_result

  • debug: msg=“{{ps_result.stdout}}”

  • debug: msg=“{{ps_result.stderr}}”

We are also running activemq which uses java processes, so we have to exclude that from our grep results.