mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Enable/disable crash detection on setting change in config
This commit is contained in:
parent
9164a89eed
commit
3995560ba2
@ -179,6 +179,15 @@ class Controller:
|
||||
logger.warning(f"Unable to find server object for server id {server_id}")
|
||||
return False
|
||||
|
||||
def crash_detection(self, server_obj):
|
||||
svr = self.get_server_obj(server_obj.server_id)
|
||||
#start or stop crash detection depending upon user preference
|
||||
#The below functions check to see if the server is running. They only execute if it's running.
|
||||
if server_obj.crash_detection == 1:
|
||||
svr.start_crash_detection()
|
||||
else:
|
||||
svr.stop_crash_detection()
|
||||
|
||||
def get_server_obj(self, server_id: Union[str, int]) -> Union[bool, Server]:
|
||||
for s in self.servers_list:
|
||||
if str(s['server_id']) == str(server_id):
|
||||
|
@ -313,6 +313,22 @@ class Server:
|
||||
'error': translation.translate('error', 'internet', user_lang)
|
||||
})
|
||||
|
||||
def stop_crash_detection(self):
|
||||
#This is only used if the crash detection settings change while the server is running.
|
||||
if self.check_running():
|
||||
logger.info(f"Detected crash detection shut off for server {self.name}")
|
||||
try:
|
||||
self.server_scheduler.remove_job('c_' + str(self.server_id))
|
||||
except:
|
||||
logger.error(f"Removing crash watcher for server {self.name} failed. Assuming it was never started.")
|
||||
|
||||
def start_crash_detection(self):
|
||||
#This is only used if the crash detection settings change while the server is running.
|
||||
if self.check_running():
|
||||
logger.info(f"Server {self.name} has crash detection enabled - starting watcher task")
|
||||
console.info(f"Server {self.name} has crash detection enabled - starting watcher task")
|
||||
self.server_scheduler.add_job(self.detect_crash, 'interval', seconds=30, id=f"c_{self.server_id}")
|
||||
|
||||
def stop_threaded_server(self):
|
||||
self.stop_server()
|
||||
|
||||
@ -325,7 +341,10 @@ class Server:
|
||||
if self.settings['crash_detection']:
|
||||
#remove crash detection watcher
|
||||
logger.info(f"Removing crash watcher for server {self.name}")
|
||||
self.server_scheduler.remove_job('c_' + str(self.server_id))
|
||||
try:
|
||||
self.server_scheduler.remove_job('c_' + str(self.server_id))
|
||||
except:
|
||||
logger.error(f"Removing crash watcher for server {self.name} failed. Assuming it was never started.")
|
||||
else:
|
||||
#windows will need to be handled separately for Ctrl+C
|
||||
self.process.terminate()
|
||||
|
@ -968,6 +968,7 @@ class PanelHandler(BaseHandler):
|
||||
server_obj.crash_detection = crash_detection
|
||||
server_obj.logs_delete_after = logs_delete_after
|
||||
self.controller.servers.update_server(server_obj)
|
||||
self.controller.crash_detection(server_obj)
|
||||
|
||||
self.controller.refresh_server_settings(server_id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user