MCPcopy Create free account
hub / github.com/apache/cloudstack / isPidMatchPidFile

Function isPidMatchPidFile

systemvm/debian/root/monitorServices.py:109–146  ·  view source on GitHub ↗

Compares the running process pid with the pid in pid file. If a process with multiple pids then it matches with pid file

(pidfile, pids)

Source from the content-addressed store, hash-verified

107
108
109def isPidMatchPidFile(pidfile, pids):
110 """ Compares the running process pid with the pid in pid file.
111 If a process with multiple pids then it matches with pid file
112 """
113
114 if pids is None or isinstance(pids,list) != True or len(pids) == 0:
115 printd ("Invalid Arguments")
116 return StatusCodes.FAILED
117 if not path.isfile(pidfile):
118 #It seems there is no pid file for this service
119 printd("The pid file "+pidfile+" is not there for this process")
120 return StatusCodes.FAILED
121
122 fd=None
123 try:
124 fd = open(pidfile,'r')
125 except:
126 printd("pid file: "+ pidfile +" open failed")
127 return StatusCodes.FAILED
128
129
130 inp = fd.read()
131
132 if not inp:
133 fd.close()
134 return StatusCodes.FAILED
135
136 printd("file content of pidfile " + pidfile + " = " + str(inp).strip())
137 printd(pids)
138 tocheck_pid = inp.strip()
139 for item in pids:
140 if str(tocheck_pid) == item.strip():
141 printd("pid file matched")
142 fd.close()
143 return StatusCodes.SUCCESS
144
145 fd.close()
146 return StatusCodes.FAILED
147
148def checkProcessRunningStatus(process_name, pidFile):
149 printd("checking the process " + process_name)

Callers 1

Calls 3

printdFunction · 0.85
closeMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected