From 1474f337bbcfbfaecf6dc371cc8fb3bcba2b467b Mon Sep 17 00:00:00 2001 From: Noah Lavine Date: Thu, 12 Oct 2017 14:30:37 -0400 Subject: [PATCH] Check for eap in the environment of running processes 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. --- library/spit_results.py | 40 +++++++++++++++++++++++++++------- roles/jboss_eap/tasks/main.yml | 2 +- test/test_spit_results.py | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/library/spit_results.py b/library/spit_results.py index 5f04da7..1d08163 100644 --- a/library/spit_results.py +++ b/library/spit_results.py @@ -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 @@ -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' diff --git a/roles/jboss_eap/tasks/main.yml b/roles/jboss_eap/tasks/main.yml index 60afff0..16c3637 100644 --- a/roles/jboss_eap/tasks/main.yml +++ b/roles/jboss_eap/tasks/main.yml @@ -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' diff --git a/test/test_spit_results.py b/test/test_spit_results.py index d84ccb8..37db839 100644 --- a/test/test_spit_results.py +++ b/test/test_spit_results.py @@ -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):