mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 11:11:32 +00:00
28 lines
888 B
Python
28 lines
888 B
Python
import xmlrpc.client
|
|
from contextlib import suppress
|
|
from xmlrpc.client import Fault as SupervisorFault
|
|
from os import remove
|
|
|
|
from tfw.config import tfwenv
|
|
|
|
|
|
class SupervisorMixin:
|
|
supervisor = xmlrpc.client.ServerProxy(tfwenv.SUPERVISOR_HTTP_URI).supervisor
|
|
|
|
def stop_process(self, process_name):
|
|
with suppress(SupervisorFault):
|
|
self.supervisor.stopProcess(process_name)
|
|
|
|
def start_process(self, process_name):
|
|
self.supervisor.startProcess(process_name)
|
|
|
|
def read_log(self, process_name):
|
|
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)
|