summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-04-11 14:48:11 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:21:37 +0530
commit210b28d84f91050fd4a293653d0f5982ae34f189 (patch)
treea7b242951236305fc32456bcc4121765f892e480
parent2291ee47cd28dab12141fb6c4118d1484f8f5dd6 (diff)
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 <rnachimu@redhat.com>
-rwxr-xr-xplugins/discovery.py20
1 files changed, 18 insertions, 2 deletions
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)