Merge branch 'pretzel-fix' into 'dev'

Pretzel fix

See merge request crafty-controller/crafty-commander!111
This commit is contained in:
Andrew 2021-12-09 23:41:13 +00:00
commit b6cf8390ad
5 changed files with 26 additions and 15 deletions

View File

@ -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):

View File

@ -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']))

View File

@ -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()

View File

@ -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()

View File

@ -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()