Alon Bar-Lev has uploaded a new change for review. Change subject: packaging: engine-service: use kill to detect running processes ......................................................................
packaging: engine-service: use kill to detect running processes Change-Id: I20238c634c418029c669bdf2b4b77e329b39faa1 Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M packaging/fedora/engine-service.py.in 1 file changed, 13 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/13414/1 diff --git a/packaging/fedora/engine-service.py.in b/packaging/fedora/engine-service.py.in index bbbb312..f487f89 100644 --- a/packaging/fedora/engine-service.py.in +++ b/packaging/fedora/engine-service.py.in @@ -276,6 +276,14 @@ jbossConfigFile = os.path.join(engineTmpDir, "engine-service.xml") +def isProcessRunning(pid): + try: + os.kill(pid, 0) + return True + except OSError: + return False + + def checkOwnership(name, uid=None, gid=None): # Get the metadata of the file: st = os.stat(name) @@ -386,7 +394,7 @@ # process is running and tell the user that the service needs # to be restarted: if enginePid: - if not os.path.exists("/proc/%d" % enginePid): + if not isProcessRunning(enginePid): raise Exception( "The engine PID file \"%s\" contains %d but " "that process doesn't exist. This means that " @@ -610,7 +618,7 @@ return # First check that the process exists: - if not os.path.exists("/proc/%d" % enginePid): + if not isProcessRunning(enginePid): syslog.syslog(syslog.LOG_WARNING, "The engine PID file \"%s\" contains %d, but that process doesn't exist, will just remove the file." % (enginePidFile, enginePid)) removeEnginePid() return @@ -624,7 +632,7 @@ os.kill(enginePid, signal.SIGTERM) initialTime = time.time() timeElapsed = 0 - while os.path.exists("/proc/%d" % enginePid): + while isProcessRunning(enginePid): syslog.syslog(syslog.LOG_INFO, "Waiting up to %d seconds for engine process %d to finish." % ((stopTime - timeElapsed), enginePid)) timeElapsed = time.time() - initialTime if timeElapsed > stopTime: @@ -633,7 +641,7 @@ # If the process didn't dissapear after the allowed time then we forcibly # kill it: - if os.path.exists("/proc/%d" % enginePid): + if isProcessRunning(enginePid): syslog.syslog(syslog.LOG_WARNING, "The engine process %d didn't finish after waiting %d seconds, killing it." % (enginePid, timeElapsed)) os.kill(enginePid, signal.SIGKILL) syslog.syslog(syslog.LOG_WARNING, "Killed engine process %d." % enginePid) @@ -676,7 +684,7 @@ sys.exit(3) # Now check that the process exists: - if not os.path.exists("/proc/%d" % enginePid): + if not isProcessRunning(enginePid): print("The engine process %d is not running." % enginePid) sys.exit(1) -- To view, visit http://gerrit.ovirt.org/13414 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I20238c634c418029c669bdf2b4b77e329b39faa1 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches