|
@@ -34,7 +34,9 @@ import ConfigParser
|
|
|
import optparse
|
|
|
import shlex
|
|
|
import datetime
|
|
|
+import tempfile
|
|
|
from AmbariConfig import AmbariConfig
|
|
|
+from ambari_agent.Constants import AGENT_TMP_DIR
|
|
|
from ambari_commons import OSCheck, OSConst
|
|
|
from ambari_commons.constants import AMBARI_SUDO_BINARY
|
|
|
from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl
|
|
@@ -46,6 +48,7 @@ GROUP_ERASE_CMD = "groupdel {0}"
|
|
|
PROC_KILL_CMD = "kill -9 {0}"
|
|
|
ALT_DISP_CMD = "alternatives --display {0}"
|
|
|
ALT_ERASE_CMD = "alternatives --remove {0} {1}"
|
|
|
+RUN_HOST_CHECKS_CMD = '/var/lib/ambari-agent/cache/custom_actions/scripts/check_host.py ACTIONEXECUTE {0} /var/lib/ambari-agent/cache/custom_actions {1} INFO {2}'
|
|
|
|
|
|
REPO_PATH_RHEL = "/etc/yum.repos.d"
|
|
|
REPO_PATH_SUSE = "/etc/zypp/repos.d/"
|
|
@@ -492,6 +495,19 @@ class HostCleanup:
|
|
|
(stdoutdata, stderrdata) = process.communicate()
|
|
|
return process.returncode, stdoutdata, stderrdata
|
|
|
|
|
|
+ def run_check_hosts(self):
|
|
|
+ config_json = '{"commandParams": {"check_execute_list": "*BEFORE_CLEANUP_HOST_CHECKS*"}}'
|
|
|
+ with tempfile.NamedTemporaryFile(delete=False) as config_json_file:
|
|
|
+ config_json_file.write(config_json)
|
|
|
+
|
|
|
+ with tempfile.NamedTemporaryFile(delete=False) as tmp_output_file:
|
|
|
+ tmp_output_file.write('{}')
|
|
|
+
|
|
|
+ run_checks_command = RUN_HOST_CHECKS_CMD.format(config_json_file.name, tmp_output_file.name, AGENT_TMP_DIR)
|
|
|
+ (returncode, stdoutdata, stderrdata) = self.run_os_command(run_checks_command)
|
|
|
+ if returncode != 0:
|
|
|
+ logger.warn('Failed to run host checks,\nstderr:\n ' + stderrdata + '\n\nstdout:\n' + stdoutdata)
|
|
|
+
|
|
|
# Copy file and save with file.# (timestamp)
|
|
|
def backup_file(filePath):
|
|
|
if filePath is not None and os.path.exists(filePath):
|
|
@@ -584,7 +600,17 @@ def main():
|
|
|
sys.exit(1)
|
|
|
|
|
|
hostcheckfile, hostcheckfileca = options.inputfiles.split(",")
|
|
|
-
|
|
|
+
|
|
|
+ # Manage non UI install
|
|
|
+ if not os.path.exists(hostcheckfileca):
|
|
|
+ if options.silent:
|
|
|
+ print 'Host Check results not found. There is no {0}. Running host checks.'.format(hostcheckfileca)
|
|
|
+ h.run_check_hosts()
|
|
|
+ else:
|
|
|
+ run_check_hosts_input = get_YN_input('Host Check results not found. There is no {0}. Do you want to run host checks [y/n] (y)'.format(hostcheckfileca), True)
|
|
|
+ if run_check_hosts_input:
|
|
|
+ h.run_check_hosts()
|
|
|
+
|
|
|
with open(TMP_HOST_CHECK_FILE_NAME, "wb") as tmp_f:
|
|
|
with open(hostcheckfile, "rb") as f1:
|
|
|
with open(hostcheckfileca, "rb") as f2:
|