baseimage-tutorial-framework/lib/tfw/components/mixins/supervisor_mixin.py

28 lines
888 B
Python
Raw Normal View History

2018-02-13 16:51:19 +00:00
import xmlrpc.client
from contextlib import suppress
from xmlrpc.client import Fault as SupervisorFault
2018-03-08 15:05:44 +00:00
from os import remove
2018-02-13 16:51:19 +00:00
from tfw.config import tfwenv
class SupervisorMixin:
supervisor = xmlrpc.client.ServerProxy(tfwenv.SUPERVISOR_HTTP_URI).supervisor
def stop_process(self, process_name):
2018-02-13 16:51:19 +00:00
with suppress(SupervisorFault):
self.supervisor.stopProcess(process_name)
2018-02-13 16:51:19 +00:00
def start_process(self, process_name):
self.supervisor.startProcess(process_name)
2018-02-13 16:51:19 +00:00
def read_log(self, process_name):
2018-03-08 15:05:44 +00:00
logs = self.supervisor.readProcessStderrLog(process_name, 0, 0)
remove(self.supervisor.getProcessInfo(process_name)['stderr_logfile'])
self.supervisor.clearProcessLogs(process_name)
return logs
def restart_process(self, process_name):
self.stop_process(process_name)
self.start_process(process_name)