From 635f671fd9735d6a69f9c0957969a3d368d25a84 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 9 Dec 2021 17:58:36 -0500 Subject: [PATCH 1/2] Move internet check to start after server has started. --- app/classes/shared/server.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 4584b348..f91fd264 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -257,20 +257,6 @@ class Server: 'error': translation.translate('error', 'start-error', user_lang).format(self.name, ex) }) return False - if user_id: - if helper.check_internet(): - loc_server_port = servers_helper.get_server_stats_by_id(self.server_id)['server_port'] - if helper.check_port(loc_server_port): - websocket_helper.broadcast_user(user_id, 'send_start_reload', { - }) - else: - websocket_helper.broadcast_user(user_id, 'send_start_error', { - 'error': translation.translate('error', 'closedPort', user_lang).format(loc_server_port) - }) - else: - websocket_helper.broadcast_user(user_id, 'send_start_error', { - 'error': translation.translate('error', 'internet', user_lang) - }) servers_helper.set_waiting_start(self.server_id, False) out_buf = ServerOutBuf(self.process, self.server_id) @@ -295,6 +281,20 @@ class Server: console.info("Server {} has crash detection enabled - starting watcher task".format(self.name)) self.crash_watcher_schedule = schedule.every(30).seconds.do(self.detect_crash).tag(self.name) + if user_id: + if helper.check_internet(): + loc_server_port = servers_helper.get_server_stats_by_id(self.server_id)['server_port'] + if helper.check_port(loc_server_port): + websocket_helper.broadcast_user(user_id, 'send_start_reload', { + }) + else: + websocket_helper.broadcast_user(user_id, 'send_start_error', { + 'error': translation.translate('error', 'closedPort', user_lang).format(loc_server_port) + }) + else: + websocket_helper.broadcast_user(user_id, 'send_start_error', { + 'error': translation.translate('error', 'internet', user_lang) + }) def stop_threaded_server(self): self.stop_server() From 8999a9a5c3b116d12e7463b1b0ee6e086e0251a0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 9 Dec 2021 18:35:00 -0500 Subject: [PATCH 2/2] Fix bug where terminal will not exit --- app/classes/shared/cmd.py | 3 +++ app/classes/shared/main_controller.py | 4 ++++ app/classes/shared/tasks.py | 2 ++ main.py | 4 +++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/classes/shared/cmd.py b/app/classes/shared/cmd.py index d9cd6832..bed2e798 100644 --- a/app/classes/shared/cmd.py +++ b/app/classes/shared/cmd.py @@ -5,6 +5,8 @@ import time import threading import logging +from app.classes.shared.tasks import TasksManager + logger = logging.getLogger(__name__) from app.classes.shared.console import console @@ -35,6 +37,7 @@ class MainPrompt(cmd.Cmd, object): pass def do_exit(self, line): + self.tasks_manager._main_graceful_exit() self.universal_exit() def do_migrations(self, line): diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 11edcf2f..22b1cf59 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -168,6 +168,7 @@ class Controller: return running_servers def stop_all_servers(self): + print("in stop all servers") servers = self.list_running_servers() logger.info("Found {} running server(s)".format(len(servers))) console.info("Found {} running server(s)".format(len(servers))) @@ -175,7 +176,10 @@ class Controller: logger.info("Stopping All Servers") console.info("Stopping All Servers") + print(servers) + for s in servers: + print(s) logger.info("Stopping Server ID {} - {}".format(s['id'], s['name'])) console.info("Stopping Server ID {} - {}".format(s['id'], s['name'])) diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index 47e390b9..4e64a314 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -109,7 +109,9 @@ class TasksManager: time.sleep(1) def _main_graceful_exit(self): + print("in graceful") try: + print("in try") os.remove(helper.session_file) os.remove(os.path.join(helper.root_dir, '.header')) self.controller.stop_all_servers() diff --git a/main.py b/main.py index 25c509f2..0762e7e3 100644 --- a/main.py +++ b/main.py @@ -152,6 +152,7 @@ if __name__ == '__main__': print() # for newline logger.info("Recieved SIGTERM, stopping Crafty") console.info("Recieved SIGTERM, stopping Crafty") + tasks_manager._main_graceful_exit() Crafty.universal_exit() signal.signal(signal.SIGTERM, sigterm_handler) @@ -163,6 +164,7 @@ if __name__ == '__main__': print() # for newline logger.info("Recieved SIGINT, stopping Crafty") console.info("Recieved SIGINT, stopping Crafty") + tasks_manager._main_graceful_exit() Crafty.universal_exit() else: print("Crafty started in daemon mode, no shell will be printed") @@ -175,5 +177,5 @@ if __name__ == '__main__': logger.info("Recieved SIGINT, stopping Crafty") console.info("Recieved SIGINT, stopping Crafty") break - + tasks_manager._main_graceful_exit() Crafty.universal_exit()