Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
rpcinterface = childutils.getRPCInterface(os.environ)
while 1:
headers, payload = childutils.listener.wait()
if headers['eventname'].startswith('PROCESS_COMMUNICATION'):
pheaders, pdata = childutils.eventdata(payload)
pname = '%s:%s' % (pheaders['processname'], pheaders['groupname'])
rpcinterface.supervisor.sendProcessStdin(pname, 'Got it yo\n')
childutils.listener.ok()
def main(maxkb):
rpc = childutils.getRPCInterface(os.environ)
while 1:
headers, payload = childutils.listener.wait()
if headers['eventname'].startswith('PROCESS_COMMUNICATION'):
pheaders, pdata = childutils.eventdata(payload)
procname, groupname = pheaders['processname'], pheaders['groupname']
if groupname == 'monitor':
for event, elem in etree.iterparse(StringIO(pdata)):
if elem.tag == 'process':
rss = int(elem.find('rss').text)
name = elem.attrib['name']
if rss > maxkb:
rpc.supervisor.stopProcess(name)
rpc.supervisor.startProcess(name)
childutils.listener.ok()
def get_supervisor():
return childutils.getRPCInterface({'SUPERVISOR_SERVER_URL':'unix:///tmp/vpnsupervisor.sock'}).supervisor
def XMLRPCClient():
"""Returns an XML-RPC client built from Supervisor's environment"""
return supervisor.childutils.getRPCInterface(os.environ)
def _restart_process(self, process_spec):
"""Restart a process.
"""
name_spec = make_namespec(
process_spec[GROUP_KEY], process_spec[NAME_KEY])
rpc_client = childutils.getRPCInterface(self._environment)
process_spec = rpc_client.supervisor.getProcessInfo(name_spec)
if process_spec[STATE_KEY] is ProcessStates.RUNNING:
self._log('Trying to stop process %s', name_spec)
try:
rpc_client.supervisor.stopProcess(name_spec)
self._log('Stopped process %s', name_spec)
except xmlrpclib.Fault as exc:
self._log('Failed to stop process %s: %s', name_spec, exc)
try:
self._log('Starting process %s', name_spec)
rpc_client.supervisor.startProcess(name_spec, False)
except xmlrpclib.Fault as exc:
self._log('Failed to start process %s: %s', name_spec, exc)
def main(every):
rpc = childutils.getRPCInterface(os.environ)
while 1:
infos = rpc.supervisor.getAllProcessInfo()
result = do(infos)
childutils.pcomm.stdout(result)
time.sleep(every)