mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-06 01:31:21 +00:00
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
import xmlrpc.client
|
|
from xmlrpc.client import Fault as SupervisorFault
|
|
from contextlib import suppress
|
|
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_stdout(self, process_name):
|
|
return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name)
|
|
|
|
def read_log_stderr(self, process_name):
|
|
return self._read_log_internal(self.supervisor.readProcessStderrLog, process_name)
|
|
|
|
def _read_log_internal(self, read_method, process_name):
|
|
log = read_method(process_name, 0, 0)
|
|
self.clear_logs(process_name)
|
|
return log
|
|
|
|
def clear_logs(self, process_name):
|
|
for logfile in ('stdout_logfile', 'stderr_logfile'):
|
|
remove(self.supervisor.getProcessInfo(process_name)[logfile])
|
|
self.supervisor.clearProcessLogs(process_name)
|
|
|
|
def restart_process(self, process_name):
|
|
self.stop_process(process_name)
|
|
self.start_process(process_name)
|