# checking java process

**URL:** <https://forum.ansible.com/t/checking-java-process/19794>\
**Category:** Ansible Project\
**Created:** [November 18, 2015, 4:07pm UTC](https://forum.ansible.com/t/checking-java-process/19794 "2015-11-18T16:07:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skr989](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@skr989](https://forum.ansible.com/u/skr989)\
**Post date:** [November 18, 2015, 4:07pm UTC](https://forum.ansible.com/t/checking-java-process/19794/1 "2015-11-18T16:07:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cosbug](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@cosbug](https://forum.ansible.com/u/cosbug)\
**Post date:** [November 19, 2015, 2:48pm UTC](https://forum.ansible.com/t/checking-java-process/19794/2 "2015-11-19T14:48:09Z")

</div>

Try this way:

when: ‘jboss.server’ in jboss\_java\_process.stdout

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 20, 2015, 11:20pm UTC](https://forum.ansible.com/t/checking-java-process/19794/3 "2015-11-20T23:20:00Z")

</div>

tasks:  
&nbsp;&nbsp;&nbsp;- name: Check JBOss java process  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: ps -f "jboss.server"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: jboss\_java\_process  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore\_errors: false

&nbsp;&nbsp;&nbsp;- debug: msg="JBoss Process is running on {{ inventory\_hostname }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: jboss\_java\_process.stdout\_lines|length \> 0

---

<div class="post-metadata">

**Author:** ![rup](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rup](https://forum.ansible.com/u/rup)\
**Post date:** [December 3, 2015, 5:28pm UTC](https://forum.ansible.com/t/checking-java-process/19794/4 "2015-12-03T17:28:17Z")

</div>

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.
