2018-04-03 12:49:14 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-02-13 16:51:19 +00:00
|
|
|
import xmlrpc.client
|
|
|
|
from xmlrpc.client import Fault as SupervisorFault
|
2018-03-25 13:43:59 +00:00
|
|
|
from contextlib import suppress
|
2018-03-08 15:05:44 +00:00
|
|
|
from os import remove
|
2018-02-13 16:51:19 +00:00
|
|
|
|
2018-03-25 14:36:31 +00:00
|
|
|
from tfw.config import TFWENV
|
2018-02-13 16:51:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SupervisorMixin:
|
2018-03-25 14:36:31 +00:00
|
|
|
supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
|
2018-02-13 16:51:19 +00:00
|
|
|
|
2018-02-27 14:54:10 +00:00
|
|
|
def stop_process(self, process_name):
|
2018-02-13 16:51:19 +00:00
|
|
|
with suppress(SupervisorFault):
|
2018-02-27 14:54:10 +00:00
|
|
|
self.supervisor.stopProcess(process_name)
|
2018-02-13 16:51:19 +00:00
|
|
|
|
2018-02-27 14:54:10 +00:00
|
|
|
def start_process(self, process_name):
|
|
|
|
self.supervisor.startProcess(process_name)
|
2018-02-13 16:51:19 +00:00
|
|
|
|
2018-05-24 09:20:00 +00:00
|
|
|
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])
|
2018-03-08 15:05:44 +00:00
|
|
|
self.supervisor.clearProcessLogs(process_name)
|
2018-03-08 15:04:35 +00:00
|
|
|
|
2018-02-27 14:54:10 +00:00
|
|
|
def restart_process(self, process_name):
|
|
|
|
self.stop_process(process_name)
|
|
|
|
self.start_process(process_name)
|