mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 01:35:28 +01:00
Merge branch 'pretzel-fix' into 'dev'
Add timeout to telnet. See merge request crafty-controller/crafty-commander!112
This commit is contained in:
commit
1341730230
@ -17,6 +17,7 @@ import shutil
|
||||
from requests import get
|
||||
from contextlib import suppress
|
||||
import ctypes
|
||||
import telnetlib
|
||||
|
||||
from datetime import datetime
|
||||
from socket import gethostname
|
||||
@ -98,14 +99,9 @@ class Helpers:
|
||||
def check_port(server_port):
|
||||
try:
|
||||
host_public = get('https://api.ipify.org').text
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(10.0)
|
||||
result = sock.connect_ex((host_public ,server_port))
|
||||
sock.close()
|
||||
if result == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
tn = telnetlib.Telnet(host_public, server_port, 10)
|
||||
telnetlib.close()
|
||||
return True
|
||||
except Exception as err:
|
||||
return False
|
||||
|
||||
|
@ -168,7 +168,6 @@ 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)))
|
||||
@ -176,10 +175,7 @@ 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']))
|
||||
|
||||
|
@ -272,6 +272,8 @@ class Server:
|
||||
console.info("Server {} running with PID {}".format(self.name, self.process.pid))
|
||||
self.is_crashed = False
|
||||
self.stats.record_stats()
|
||||
websocket_helper.broadcast_user(user_id, 'send_start_reload', {
|
||||
})
|
||||
else:
|
||||
logger.warning("Server PID {} died right after starting - is this a server config issue?".format(self.process.pid))
|
||||
console.warning("Server PID {} died right after starting - is this a server config issue?".format(self.process.pid))
|
||||
@ -281,13 +283,25 @@ 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)
|
||||
|
||||
check_port_thread = threading.Thread(target=self.check_internet_thread, daemon=True, args=(user_id, user_lang, ), name=f"backup_{self.name}")
|
||||
check_port_thread.start()
|
||||
|
||||
def check_internet_thread(self, user_id, user_lang):
|
||||
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:
|
||||
port_status = False
|
||||
|
||||
for i in range(1):
|
||||
if helper.check_port(loc_server_port):
|
||||
port_status = True
|
||||
return
|
||||
else:
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if port_status == False:
|
||||
websocket_helper.broadcast_user(user_id, 'send_start_error', {
|
||||
'error': translation.translate('error', 'closedPort', user_lang).format(loc_server_port)
|
||||
})
|
||||
@ -295,6 +309,7 @@ class Server:
|
||||
websocket_helper.broadcast_user(user_id, 'send_start_error', {
|
||||
'error': translation.translate('error', 'internet', user_lang)
|
||||
})
|
||||
return
|
||||
|
||||
def stop_threaded_server(self):
|
||||
self.stop_server()
|
||||
|
@ -109,9 +109,7 @@ 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user