Skip to content

Commit 7dceca5

Browse files
author
Jayapal
committed
CLOUDSTACK-5177: Fixed issue with running script from cron job
1 parent 9410423 commit 7dceca5

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

systemvm/patches/debian/config/opt/cloud/bin/monitor_service.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ crontab -l | grep -v monitorServices.py | crontab -
6464
create_config $config
6565

6666
#add cron job
67-
(crontab -l ; echo "*/3 * * * * python /root/monitorServices.py") | crontab -
67+
(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 -
6868

6969

7070
unlock_exit 0 $lock $locked

systemvm/patches/debian/config/root/monitorServices.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ def getConfig( config_file_path = "/etc/monitor.conf" ):
6262
return process_dict
6363

6464
def printd (msg):
65+
6566
return 0
66-
print msg
67+
68+
f= open(monitor_log,'r+')
69+
f.seek(0, 2)
70+
f.write(str(msg)+"\n")
71+
f.close()
6772

6873
def raisealert(severity, msg, process_name=None):
6974
#timeStr=str(time.ctime())
@@ -76,12 +81,6 @@ def raisealert(severity, msg, process_name=None):
7681
pout = Popen(msg, shell=True, stdout=PIPE)
7782

7883

79-
#f= open(monitor_log,'r+')
80-
#f.seek(0, 2)
81-
#f.write(str(log))
82-
#f.close()
83-
84-
8584
def isPidMatchPidFile(pidfile, pids):
8685

8786
if pids is None or isinstance(pids,list) != True or len(pids) == 0:
@@ -119,7 +118,7 @@ def checkProcessStatus( process ):
119118
service_name = process.get('servicename')
120119
pidfile = process.get('pidfile')
121120
#temp_out = None
122-
restartFailed=0
121+
restartFailed=False
123122
pidFileMatched=1
124123
cmd=''
125124
if process_name is None:
@@ -186,34 +185,32 @@ def checkProcessStatus( process ):
186185
for pid in pids:
187186
cmd = 'kill -9 '+pid;
188187
printd(cmd)
189-
Popen(cmd, shell=True, stdout=PIPE)
188+
Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
190189

191190
cmd = 'service ' + service_name + ' restart'
192-
try:
193-
time.sleep(1)
194-
return_val= check_call(cmd , shell=True)
195-
except CalledProcessError:
196-
restartFailed=1
197-
msg="service "+ process_name +" restart failed"
198-
printd(msg)
199-
continue
191+
192+
time.sleep(1)
193+
#return_val= check_call(cmd , shell=True)
194+
195+
cout = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
196+
return_val = cout.wait()
200197

201198
if return_val == 0:
202199
printd("The process" + process_name +" recovered successfully ")
203200
msg="The process " +process_name+" is recovered successfully "
204-
raisealert(log.INFO,process_name,msg)
201+
raisealert(log.INFO,msg,process_name)
205202

206203
break;
207204
else:
208205
#retry restarting the process for few tries
209206
printd("process restart failing trying again ....")
210-
restartFailed=1
207+
restartFailed=True
211208
time.sleep(1)
212209
continue
213210
#for end here
214211

215-
if restartFailed == 1:
216-
msg="The process %s recover failed ", process_name;
212+
if restartFailed == True:
213+
msg="The process %s recover failed "%process_name
217214
raisealert(log.ALERT,process_name,msg)
218215

219216
printd("Restart failed after number of retries")

0 commit comments

Comments
 (0)