mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'fix/exit-code-tweak' into 'dev'
removed old exit handling logic See merge request crafty-controller/crafty-commander!109
This commit is contained in:
commit
12153b1207
@ -34,17 +34,6 @@ class MainPrompt(cmd.Cmd, object):
|
|||||||
def emptyline():
|
def emptyline():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _clean_shutdown():
|
|
||||||
exit_file = os.path.join(helper.root_dir, "exit.txt")
|
|
||||||
try:
|
|
||||||
with open(exit_file, 'w') as f:
|
|
||||||
f.write("exit")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical("Unable to write exit file due to error: {}".format(e))
|
|
||||||
console.critical("Unable to write exit file due to error: {}".format(e))
|
|
||||||
|
|
||||||
def do_exit(self, line):
|
def do_exit(self, line):
|
||||||
self.universal_exit()
|
self.universal_exit()
|
||||||
|
|
||||||
@ -77,7 +66,6 @@ class MainPrompt(cmd.Cmd, object):
|
|||||||
logger.info("Stopping all server daemons / threads")
|
logger.info("Stopping all server daemons / threads")
|
||||||
console.info("Stopping all server daemons / threads - This may take a few seconds")
|
console.info("Stopping all server daemons / threads - This may take a few seconds")
|
||||||
websocket_helper.disconnect_all()
|
websocket_helper.disconnect_all()
|
||||||
self._clean_shutdown()
|
|
||||||
console.info('Waiting for main thread to stop')
|
console.info('Waiting for main thread to stop')
|
||||||
while True:
|
while True:
|
||||||
if self.tasks_manager.get_main_thread_run_status():
|
if self.tasks_manager.get_main_thread_run_status():
|
||||||
|
@ -230,16 +230,6 @@ class Helpers:
|
|||||||
version_data.get('meta', '?'))
|
version_data.get('meta', '?'))
|
||||||
return str(version)
|
return str(version)
|
||||||
|
|
||||||
def do_exit(self):
|
|
||||||
exit_file = os.path.join(self.root_dir, 'exit.txt')
|
|
||||||
try:
|
|
||||||
open(exit_file, 'a').close()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical("Unable to create exit file!")
|
|
||||||
console.critical("Unable to create exit file!")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def encode_pass(self, password):
|
def encode_pass(self, password):
|
||||||
return self.passhasher.hash(password)
|
return self.passhasher.hash(password)
|
||||||
|
|
||||||
|
@ -171,12 +171,10 @@ class Server:
|
|||||||
if not helper.check_path_exists(self.server_path):
|
if not helper.check_path_exists(self.server_path):
|
||||||
logger.critical("Server path: {} does not seem to exits".format(self.server_path))
|
logger.critical("Server path: {} does not seem to exits".format(self.server_path))
|
||||||
console.critical("Server path: {} does not seem to exits".format(self.server_path))
|
console.critical("Server path: {} does not seem to exits".format(self.server_path))
|
||||||
helper.do_exit()
|
|
||||||
|
|
||||||
if not helper.check_writeable(self.server_path):
|
if not helper.check_writeable(self.server_path):
|
||||||
logger.critical("Unable to write/access {}".format(self.server_path))
|
logger.critical("Unable to write/access {}".format(self.server_path))
|
||||||
console.warning("Unable to write/access {}".format(self.server_path))
|
console.warning("Unable to write/access {}".format(self.server_path))
|
||||||
helper.do_exit()
|
|
||||||
|
|
||||||
def start_server(self, user_id):
|
def start_server(self, user_id):
|
||||||
if not user_id:
|
if not user_id:
|
||||||
|
@ -48,7 +48,6 @@ class TasksManager:
|
|||||||
|
|
||||||
self.webserver_thread = threading.Thread(target=self.tornado.run_tornado, daemon=True, name='tornado_thread')
|
self.webserver_thread = threading.Thread(target=self.tornado.run_tornado, daemon=True, name='tornado_thread')
|
||||||
|
|
||||||
self.main_kill_switch_thread = threading.Thread(target=self.main_kill_switch, daemon=True, name="main_loop")
|
|
||||||
self.main_thread_exiting = False
|
self.main_thread_exiting = False
|
||||||
|
|
||||||
self.schedule_thread = threading.Thread(target=self.scheduler_thread, daemon=True, name="scheduler")
|
self.schedule_thread = threading.Thread(target=self.scheduler_thread, daemon=True, name="scheduler")
|
||||||
@ -65,16 +64,6 @@ class TasksManager:
|
|||||||
def get_main_thread_run_status(self):
|
def get_main_thread_run_status(self):
|
||||||
return self.main_thread_exiting
|
return self.main_thread_exiting
|
||||||
|
|
||||||
def start_main_kill_switch_watcher(self):
|
|
||||||
self.main_kill_switch_thread.start()
|
|
||||||
|
|
||||||
def main_kill_switch(self):
|
|
||||||
while True:
|
|
||||||
if os.path.exists(os.path.join(helper.root_dir, 'exit.txt')):
|
|
||||||
logger.info("Found Exit File, stopping everything")
|
|
||||||
self._main_graceful_exit()
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
def reload_schedule_from_db(self):
|
def reload_schedule_from_db(self):
|
||||||
jobs = management_helper.get_schedules_enabled()
|
jobs = management_helper.get_schedules_enabled()
|
||||||
schedule.clear(tag='backup')
|
schedule.clear(tag='backup')
|
||||||
@ -122,7 +111,6 @@ class TasksManager:
|
|||||||
def _main_graceful_exit(self):
|
def _main_graceful_exit(self):
|
||||||
try:
|
try:
|
||||||
os.remove(helper.session_file)
|
os.remove(helper.session_file)
|
||||||
os.remove(os.path.join(helper.root_dir, 'exit.txt'))
|
|
||||||
os.remove(os.path.join(helper.root_dir, '.header'))
|
os.remove(os.path.join(helper.root_dir, '.header'))
|
||||||
self.controller.stop_all_servers()
|
self.controller.stop_all_servers()
|
||||||
except:
|
except:
|
||||||
|
3
main.py
3
main.py
@ -137,9 +137,6 @@ if __name__ == '__main__':
|
|||||||
# refresh our cache and schedule for every 12 hoursour cache refresh for serverjars.com
|
# refresh our cache and schedule for every 12 hoursour cache refresh for serverjars.com
|
||||||
tasks_manager.serverjar_cache_refresher()
|
tasks_manager.serverjar_cache_refresher()
|
||||||
|
|
||||||
# this should always be last
|
|
||||||
tasks_manager.start_main_kill_switch_watcher()
|
|
||||||
|
|
||||||
logger.info("Checking Internet/Port Service. This may take a minute.")
|
logger.info("Checking Internet/Port Service. This may take a minute.")
|
||||||
console.info("Checking Internet/Port Service. This may take a minute.")
|
console.info("Checking Internet/Port Service. This may take a minute.")
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ cryptography~=3.4
|
|||||||
argon2-cffi~=20.1
|
argon2-cffi~=20.1
|
||||||
bleach~=3.1
|
bleach~=3.1
|
||||||
colorama~=0.4
|
colorama~=0.4
|
||||||
|
cryptography~=3.4
|
||||||
peewee~=3.13
|
peewee~=3.13
|
||||||
pexpect~=4.8
|
pexpect~=4.8
|
||||||
psutil~=5.7
|
psutil~=5.7
|
||||||
|
Loading…
Reference in New Issue
Block a user