Skip to content

Instantly share code, notes, and snippets.

@nelsoncbf
Forked from jalp/supervisor_client.py
Last active May 11, 2020 21:59
Show Gist options
  • Save nelsoncbf/a1bdc6fdcc13d246ae3168b32260732f to your computer and use it in GitHub Desktop.
Save nelsoncbf/a1bdc6fdcc13d246ae3168b32260732f to your computer and use it in GitHub Desktop.
Supervisor api client in Python
#import xmlrpclib
from xmlrpc import client
class ProcessStatus(object):
RUNNING = 'RUNNING'
STOPPED = 'STOPPED'
FATAL = 'FATAL'
RESTARTING = 'RESTARTING'
SHUTDOWN = 'SHUTDOWN'
class SupervisorClient(object):
""" Supervisor client to work with remote supervisor
"""
def __init__(self, host='localhost', port=9001):
self.server = xmlrpclib.Server('http://{}:{}/RPC2'.format(host, port))
def _generate_correct_process_name(self, process):
return "{}:1".format(process)
def start(self, process):
""" Start process
:process: process name as String
"""
return self.server.supervisor.startProcess(self._generate_correct_process_name(process))
def stop(self, process):
""" Stop process
:process: process name as String
"""
return self.server.supervisor.stopProcess(self._generate_correct_process_name(process))
def status(self, process):
""" Retrieve status process
:process: process name as String
"""
return self.server.supervisor.getProcessInfo(self._generate_correct_process_name(process))['statename']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment