Check the process running status, if not running tries to restart Returns the process status and if it was restarted
( process )
| 189 | return False |
| 190 | |
| 191 | def checkProcessStatus( process ): |
| 192 | """ |
| 193 | Check the process running status, if not running tries to restart |
| 194 | Returns the process status and if it was restarted |
| 195 | """ |
| 196 | process_name = process.get('processname') |
| 197 | service_name = process.get('servicename') |
| 198 | pidfile = process.get('pidfile') |
| 199 | #temp_out = None |
| 200 | restartFailed=False |
| 201 | pidFileMatched=False |
| 202 | pids='' |
| 203 | cmd='' |
| 204 | if process_name is None: |
| 205 | printd ("\n Invalid Process Name") |
| 206 | return StatusCodes.INVALID_INP, False |
| 207 | |
| 208 | status, pids = checkProcessRunningStatus(process_name, pidfile) |
| 209 | |
| 210 | if status == True: |
| 211 | printd("The process is running ....") |
| 212 | return StatusCodes.RUNNING, False |
| 213 | else: |
| 214 | printd("Process %s is not running trying to recover" %process_name) |
| 215 | #Retry the process state for few seconds |
| 216 | |
| 217 | for i in range(1, Config.RETRY_ITERATIONS): |
| 218 | time.sleep(Config.SLEEP_SEC) |
| 219 | |
| 220 | if i < Config.RETRY_FOR_RESTART: # this is just for trying few more times |
| 221 | |
| 222 | status, pids = checkProcessRunningStatus(process_name, pidfile) |
| 223 | if status == True: |
| 224 | raisealert(Log.ALERT, "The process detected as running", process_name) |
| 225 | break |
| 226 | else: |
| 227 | printd("Process %s is not running checking the status again..." %process_name) |
| 228 | continue |
| 229 | else: |
| 230 | msg="The process " +process_name+" is not running trying recover " |
| 231 | raisealert(Log.INFO,process_name,msg) |
| 232 | |
| 233 | if service_name == 'apache2': |
| 234 | # Killing apache2 process with this the main service will not start |
| 235 | for pid in pids: |
| 236 | cmd = 'kill -9 '+pid |
| 237 | printd(cmd) |
| 238 | Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) |
| 239 | |
| 240 | if restartService(service_name) == True: |
| 241 | break |
| 242 | else: |
| 243 | restartFailed = True |
| 244 | continue |
| 245 | #for end here |
| 246 | |
| 247 | if restartFailed == True: |
| 248 | msg="The process %s recover failed "%process_name |
no test coverage detected