From 210b28d84f91050fd4a293653d0f5982ae34f189 Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Fri, 11 Apr 2014 14:48:11 +0530 Subject: autoconf: don't restart nagios if it is stoped. Autoconfig script get struck when user runs the script without starting the nagios. Fixed it by checking the nagios service status before restarting. Now autoconfig will restart the nagios only if it started already by the user. Bug-Url: https://bugzilla.redhat.com/1084975 Change-Id: I1582d06abe764e6f2ae2c63d4a2e7169f0b11aa5 Signed-off-by: Ramesh Nachimuthu --- plugins/discovery.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/discovery.py b/plugins/discovery.py index 31781d8..5794c2e 100755 --- a/plugins/discovery.py +++ b/plugins/discovery.py @@ -21,7 +21,10 @@ import commands import json import datetime import re +import sys + from config_generator import GlusterNagiosConfManager +from glusternagios import utils #from glusternagios import utils from constants import DEFAULT_AUTO_CONFIG_DIR @@ -31,6 +34,9 @@ from constants import NRPE_PATH from constants import NAGIOS_COMMAND_FILE_PATH +serviceCmdPath = utils.CommandPath("service", "/sbin/service", ) + + def excecNRPECommand(command): """ This function executes NRPE command and return the result @@ -118,13 +124,21 @@ def getConfigManager(args): return configManager -def __restartNagios(): +def _restartNagios(): now = datetime.datetime.now() cmdStr = "[%s] RESTART_PROGRAM\n" % (now) with open(NAGIOS_COMMAND_FILE_PATH, "w") as f: f.write(cmdStr) +def _isNagiosRunning(): + (rc, out, err) = utils.execCmd([serviceCmdPath.cmd, 'nagios', 'status']) + if rc == 0: + return True + else: + return False + + if __name__ == '__main__': args = parse_input() clusterdata = discovercluster(args) @@ -133,4 +147,6 @@ if __name__ == '__main__': clusterdata) print " Cluster configurations re-synced successfully from host %s" % \ (args.hostip) - __restartNagios() + if _isNagiosRunning(): + _restartNagios() + sys.exit(utils.PluginStatusCode.OK) -- cgit