Commit 84bba7b6 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: sup_process library upgraded (new functions, fixes)

parent de01a150
import os
import signal
import time import time
import xmlrpclib import xmlrpclib
...@@ -7,10 +9,18 @@ from supervisor import childutils ...@@ -7,10 +9,18 @@ from supervisor import childutils
# It aims to replace the file "process.py" # It aims to replace the file "process.py"
# For the moment, we keep both for compatibility # For the moment, we keep both for compatibility
def isRunning(config, process): def isRunning(config, process):
server = xmlrpclib.Server(config['supervisord_server']) server = xmlrpclib.Server(config['supervisord_server'])
state = server.supervisor.getProcessInfo(process)['state'] state = server.supervisor.getProcessInfo(process)['state']
return (True if state == 20 else False) return (True if state in (10, 20) else False)
def killRunningProcess(config, process, sig=signal.SIGTERM):
server = xmlrpclib.Server(config['supervisord_server'])
pid = server.supervisor.getProcessInfo(process)['pid']
if pid != 0:
os.kill(pid, sig)
def returnCode(config, process): def returnCode(config, process):
...@@ -31,6 +41,12 @@ def runProcesses(config, processes): ...@@ -31,6 +41,12 @@ def runProcesses(config, processes):
waitForProcessEnd(proc) waitForProcessEnd(proc)
def stopIfRunning(config, process):
if isRunning(config, process):
server = xmlrpclib.Server(config['supervisord_server'])
slapos.stopProcess(process)
def stopProcess(config, process): def stopProcess(config, process):
server = xmlrpclib.Server(config['supervisord_server']) server = xmlrpclib.Server(config['supervisord_server'])
server.supervisor.stopProcess(process) server.supervisor.stopProcess(process)
...@@ -47,5 +63,7 @@ def waitForProcessEnd(config, process): ...@@ -47,5 +63,7 @@ def waitForProcessEnd(config, process):
while True: while True:
state = server.supervisor.getProcessInfo(process)['state'] state = server.supervisor.getProcessInfo(process)['state']
if state == 20: if state == 20:
time.sleep(5) time.sleep(3)
else:
return True
return False return False
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment