diff --git a/systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh b/systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh index a2b789cac8f..c4d99d2207e 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh +++ b/systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh @@ -64,7 +64,7 @@ crontab -l | grep -v monitorServices.py | crontab - create_config $config #add cron job -(crontab -l ; echo "*/3 * * * * python /root/monitorServices.py") | crontab - +(crontab -l ;echo -e "SHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n */1 * * * * /usr/bin/python /root/monitorServices.py") | crontab - unlock_exit 0 $lock $locked diff --git a/systemvm/patches/debian/config/root/monitorServices.py b/systemvm/patches/debian/config/root/monitorServices.py index f0c2afe83a6..2cec672f0ce 100755 --- a/systemvm/patches/debian/config/root/monitorServices.py +++ b/systemvm/patches/debian/config/root/monitorServices.py @@ -62,8 +62,13 @@ def getConfig( config_file_path = "/etc/monitor.conf" ): return process_dict def printd (msg): + return 0 - print msg + + f= open(monitor_log,'r+') + f.seek(0, 2) + f.write(str(msg)+"\n") + f.close() def raisealert(severity, msg, process_name=None): #timeStr=str(time.ctime()) @@ -76,12 +81,6 @@ def raisealert(severity, msg, process_name=None): pout = Popen(msg, shell=True, stdout=PIPE) - #f= open(monitor_log,'r+') - #f.seek(0, 2) - #f.write(str(log)) - #f.close() - - def isPidMatchPidFile(pidfile, pids): if pids is None or isinstance(pids,list) != True or len(pids) == 0: @@ -119,7 +118,7 @@ def checkProcessStatus( process ): service_name = process.get('servicename') pidfile = process.get('pidfile') #temp_out = None - restartFailed=0 + restartFailed=False pidFileMatched=1 cmd='' if process_name is None: @@ -186,34 +185,32 @@ def checkProcessStatus( process ): for pid in pids: cmd = 'kill -9 '+pid; printd(cmd) - Popen(cmd, shell=True, stdout=PIPE) + Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) cmd = 'service ' + service_name + ' restart' - try: - time.sleep(1) - return_val= check_call(cmd , shell=True) - except CalledProcessError: - restartFailed=1 - msg="service "+ process_name +" restart failed" - printd(msg) - continue + + time.sleep(1) + #return_val= check_call(cmd , shell=True) + + cout = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) + return_val = cout.wait() if return_val == 0: printd("The process" + process_name +" recovered successfully ") msg="The process " +process_name+" is recovered successfully " - raisealert(log.INFO,process_name,msg) + raisealert(log.INFO,msg,process_name) break; else: #retry restarting the process for few tries printd("process restart failing trying again ....") - restartFailed=1 + restartFailed=True time.sleep(1) continue #for end here - if restartFailed == 1: - msg="The process %s recover failed ", process_name; + if restartFailed == True: + msg="The process %s recover failed "%process_name raisealert(log.ALERT,process_name,msg) printd("Restart failed after number of retries")