Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Check for eap in the environment of running processes
Browse files Browse the repository at this point in the history
That matches several environment variables that I have observed in a
running jboss process.

Also includes a bug fix that removes a false positive process in the
process scan.
  • Loading branch information
Noah Lavine committed Oct 12, 2017
1 parent 93269d9 commit 1474f33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
40 changes: 32 additions & 8 deletions library/spit_results.py
Expand Up @@ -401,15 +401,36 @@ def process_jboss_eap_common_dirs(fact_names, host_vars):


def process_jboss_eap_processes(fact_names, host_vars):
"""Process the output of 'pgrep -f eap'
"""Process the output of 'ps -A -f e | grep eap'
:returns: a dict of key, value pairs to add to the output.
"""

# Why use 'ps -A -f e | grep eap'? The -A gets us every process on
# the system, and -f means ps will print the command-line
# arguments, which is key because JBoss will be invoked with java
# as the executable and an argument that says to run the Wildfly
# jar.

# The e makes ps print the process's environment. It's in a format
# that is not machine-readable, because ps uses spaces as the
# delimiter for both command-line args and the process
# environment, and we have no way to tell where the arguments end
# and the environment begins. However, that's fine for grepping. I
# observed an EAP 7 application server running with MANPATH,
# JBOSS_MODULEPATH, JBOSS_HOME, WILDFLY_CONSOLE_LOG, WILDFLY_SH,
# LD_LIBRARY_PATH, EAP7_SCLS_ENABLED, PATH, WILDFLY_MODULEPATH,
# HOME, and PKG_CONFIG_PATH set to directories that included
# /opt/rh/eap7, all of which will be caught by our
# grep. Additionally, variables LAUNCH_JBOSS_IN_BACKGROUND and
# JBOSS_HOME will be caught because of the variable names
# themselves. We deliberately don't grep for wildfly or jboss,
# because that could catch non-JBoss Wildfly installations.

err, output = raw_output_present(fact_names, host_vars,
JBOSS_EAP_PROCESSES,
JBOSS_EAP_PROCESSES,
'ps -A -f | grep eap')
'ps -A -f e | grep eap')
if err is not None:
return err

Expand All @@ -420,14 +441,17 @@ def process_jboss_eap_processes(fact_names, host_vars):

num_procs = len(output['stdout_lines'])

# There should always be one process matching 'eap', which is the
# grep that's finding the other processes.
if not num_procs:
return {JBOSS_EAP_PROCESSES:
"Bad result (0 processes) from 'ps -A -f | grep eap'"}
# There should always be two processes matching 'eap', one for the
# grep that's searching for 'eap', and one for the bash that's
# running the pipeline.
if num_procs < 2:
return {
JBOSS_EAP_PROCESSES:
"Bad result ({0} processes) from 'ps -A -f e | grep eap'".format(
num_procs)}

return {JBOSS_EAP_PROCESSES:
'{0} EAP processes found'.format(num_procs - 1)}
'{0} EAP processes found'.format(num_procs - 2)}


JBOSS_EAP_PACKAGES = 'jboss.eap.packages'
Expand Down
2 changes: 1 addition & 1 deletion roles/jboss_eap/tasks/main.yml
Expand Up @@ -19,7 +19,7 @@
- /usr/log/jboss-as
when: '"jboss.eap.common-directories" in facts_to_collect'
- name: gather jboss.eap.processes
raw: ps -A -f | grep eap
raw: ps -A -f e | grep eap
register: jboss.eap.processes
ignore_errors: yes
when: '"jboss.eap.processes" in facts_to_collect'
Expand Down
2 changes: 1 addition & 1 deletion test/test_spit_results.py
Expand Up @@ -183,7 +183,7 @@ def test_no_processes(self):
def test_found_processes(self):
self.assertEqual(
self.run_func({'rc': 0, 'stdout_lines': [1, 2, 3]}),
{'jboss.eap.processes': '2 EAP processes found'})
{'jboss.eap.processes': '1 EAP processes found'})


class TestProcessJbossEapPackages(unittest.TestCase):
Expand Down

0 comments on commit 1474f33

Please sign in to comment.