diff --git a/slapos/runner/sup_process.py b/slapos/runner/sup_process.py index 2fc6c3fb82ad0d2aadb8841f80d705a4a690b59b..294c39fd94da4d9ad7bc174ce09a5a441a799e7b 100644 --- a/slapos/runner/sup_process.py +++ b/slapos/runner/sup_process.py @@ -1,3 +1,5 @@ +# pylint: disable-msg=W0311,C0103 + import os import signal import time @@ -9,12 +11,19 @@ import xmlrpclib def isRunning(config, process): + """ + Ask supervisor if given process is currently running + """ server = xmlrpclib.Server(config['supervisord_server']) state = server.supervisor.getProcessInfo(process)['state'] return (True if state in (10, 20) else False) def killRunningProcess(config, process, sig=signal.SIGTERM): + """ + Send signal "sig" to given process. + Default signal sent is SIGTERM + """ server = xmlrpclib.Server(config['supervisord_server']) pid = server.supervisor.getProcessInfo(process)['pid'] if pid != 0: @@ -22,21 +31,30 @@ def killRunningProcess(config, process, sig=signal.SIGTERM): def returnCode(config, process): + """ + Get the returned code of the last run of given process + """ server = xmlrpclib.Server(config['supervisord_server']) code = server.supervisor.getProcessInfo(process)['exitstatus'] return code def runProcess(config, process): + """ + Start a process registered by supervisor + """ server = xmlrpclib.Server(config['supervisord_server']) server.supervisor.startProcess(process) def runProcesses(config, processes): + """ + Start by supervisor a list of given processes, one by one + """ server = xmlrpclib.Server(config['supervisord_server']) for proc in processes: server.supervisor.startProcess(proc) - waitForProcessEnd(proc) + waitForProcessEnd(config, proc) def stopProcess(config, process): @@ -49,12 +67,18 @@ def stopProcess(config, process): def stopProcesses(config, processes): + """ + Stop a list of processes + """ server = xmlrpclib.Server(config['supervisord_server']) for proc in processes: server.supervisor.stopProcess(proc) def waitForProcessEnd(config, process): + """ + Block program's execution until given process quits Running state + """ server = xmlrpclib.Server(config['supervisord_server']) while True: state = server.supervisor.getProcessInfo(process)['state']