You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ja...@apache.org on 2013/11/15 07:36:39 UTC

git commit: updated refs/heads/4.3 to dd731e8

Updated Branches:
  refs/heads/4.3 b87f675f4 -> dd731e867


CLOUDSTACK-5177: Fixed issue with running script from cron job


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/dd731e86
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/dd731e86
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/dd731e86

Branch: refs/heads/4.3
Commit: dd731e867019106849d0a52cb49a205b01ec4951
Parents: b87f675
Author: Jayapal <ja...@apache.org>
Authored: Fri Nov 15 12:04:38 2013 +0530
Committer: Jayapal <ja...@apache.org>
Committed: Fri Nov 15 12:05:44 2013 +0530

----------------------------------------------------------------------
 .../config/opt/cloud/bin/monitor_service.sh     |  2 +-
 .../debian/config/root/monitorServices.py       | 39 +++++++++-----------
 2 files changed, 19 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dd731e86/systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh
----------------------------------------------------------------------
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 a2b789c..c4d99d2 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dd731e86/systemvm/patches/debian/config/root/monitorServices.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/root/monitorServices.py b/systemvm/patches/debian/config/root/monitorServices.py
index f0c2afe..2cec672 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")