checking java process

205 views
Skip to first unread message

skr...@gmail.com

unread,
Nov 18, 2015, 11:07:53 AM11/18/15
to Ansible Project
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

Co S

unread,
Nov 19, 2015, 9:48:10 AM11/19/15
to Ansible Project
Try this way:

when: 'jboss.server' in jboss_java_process.stdout

Brian Coca

unread,
Nov 20, 2015, 6:20:06 PM11/20/15
to Ansible Project
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

--
Brian Coca

rup

unread,
Dec 3, 2015, 12:28:17 PM12/3/15
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages