|
|
@ -27,6 +27,7 @@ class Management:
|
|
|
|
self.procs = {}
|
|
|
|
self.procs = {}
|
|
|
|
self.org_chart = []
|
|
|
|
self.org_chart = []
|
|
|
|
self._load_config()
|
|
|
|
self._load_config()
|
|
|
|
|
|
|
|
self.wait_restart = False
|
|
|
|
|
|
|
|
|
|
|
|
def _load_config(self):
|
|
|
|
def _load_config(self):
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config = configparser.ConfigParser()
|
|
|
@ -46,16 +47,23 @@ class Management:
|
|
|
|
Initialized and start all child bureaus
|
|
|
|
Initialized and start all child bureaus
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
for buro in self.org_chart:
|
|
|
|
for buro in self.org_chart:
|
|
|
|
# TODO: this may need some sanity checking for crash/reload
|
|
|
|
self._start_bureau(buro)
|
|
|
|
lib = importlib.import_module("bureau." + buro)
|
|
|
|
self.wait_restart = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _start_bureau(self, bureau_name):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
starts an individual bureau
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
lib = importlib.import_module("bureau." + bureau_name)
|
|
|
|
proc = multiprocessing.Process(target=lib.main)
|
|
|
|
proc = multiprocessing.Process(target=lib.main)
|
|
|
|
self.procs[buro] = proc
|
|
|
|
self.procs[bureau_name] = proc
|
|
|
|
proc.start()
|
|
|
|
proc.start()
|
|
|
|
|
|
|
|
|
|
|
|
def _stop_bureaus(self):
|
|
|
|
def _stop_bureaus(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Terminates all running bureau children
|
|
|
|
Terminates all running bureau children
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.wait_restart = True
|
|
|
|
for buro in self.org_chart:
|
|
|
|
for buro in self.org_chart:
|
|
|
|
proc = self.procs[buro]
|
|
|
|
proc = self.procs[buro]
|
|
|
|
proc.terminate()
|
|
|
|
proc.terminate()
|
|
|
@ -81,13 +89,16 @@ class Management:
|
|
|
|
|
|
|
|
|
|
|
|
self._start_bureaus()
|
|
|
|
self._start_bureaus()
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
|
|
|
|
if self.wait_restart:
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
continue
|
|
|
|
for buro in self.org_chart:
|
|
|
|
for buro in self.org_chart:
|
|
|
|
proc = self.procs[buro]
|
|
|
|
proc = self.procs[buro]
|
|
|
|
if not proc.is_alive():
|
|
|
|
if not proc.is_alive():
|
|
|
|
print("bureau", buro, "has crashed! Call the consultants!")
|
|
|
|
print("bureau", buro, "has crashed! Call the consultants!")
|
|
|
|
print("restarting...")
|
|
|
|
time.sleep(3)
|
|
|
|
#TODO this should probably only retry a few times
|
|
|
|
print("restarting", buro)
|
|
|
|
proc.start()
|
|
|
|
self._start_bureau(buro)
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|