mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Improve the startup process
This commit is contained in:
parent
eff7aefb6e
commit
b724fc500d
@ -94,6 +94,10 @@ class MainPrompt(cmd.Cmd):
|
|||||||
else:
|
else:
|
||||||
print(f"Name: {thread.name} Identifier: {thread.ident}")
|
print(f"Name: {thread.name} Identifier: {thread.ident}")
|
||||||
|
|
||||||
|
def print_prompt(self):
|
||||||
|
self.stdout.write(self.prompt)
|
||||||
|
self.stdout.flush()
|
||||||
|
|
||||||
def do_import3(self, _line):
|
def do_import3(self, _line):
|
||||||
Import3.start_import()
|
Import3.start_import()
|
||||||
|
|
||||||
|
94
main.py
94
main.py
@ -136,21 +136,17 @@ if __name__ == "__main__":
|
|||||||
tasks_manager = TasksManager(helper, controller)
|
tasks_manager = TasksManager(helper, controller)
|
||||||
tasks_manager.start_webserver()
|
tasks_manager.start_webserver()
|
||||||
|
|
||||||
def sigterm_handler(*sig):
|
def signal_handler(signum, _frame):
|
||||||
print() # for newline
|
if not args.daemon:
|
||||||
logger.info(
|
print() # for newline after prompt
|
||||||
f"Recieved {signal.Signals(sig[0]).name} [{sig[0]}], stopping Crafty..."
|
signame = signal.Signals(signum).name
|
||||||
)
|
logger.info(f"Recieved signal {signame} [{signum}], stopping Crafty...")
|
||||||
Console.info(
|
Console.info(f"Recieved signal {signame} [{signum}], stopping Crafty...")
|
||||||
f"Recieved {signal.Signals(sig[0]).name} [{sig[0]}], stopping Crafty..."
|
|
||||||
)
|
|
||||||
tasks_manager._main_graceful_exit()
|
tasks_manager._main_graceful_exit()
|
||||||
Crafty.universal_exit()
|
crafty_prompt.universal_exit()
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, sigterm_handler)
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
# slowing down reporting just for a 1/2 second so messages look cleaner
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
# init servers
|
# init servers
|
||||||
logger.info("Initializing all servers defined")
|
logger.info("Initializing all servers defined")
|
||||||
@ -171,11 +167,10 @@ if __name__ == "__main__":
|
|||||||
tasks_manager.serverjar_cache_refresher()
|
tasks_manager.serverjar_cache_refresher()
|
||||||
|
|
||||||
tasks_starter_thread = Thread(target=tasks_starter, name="tasks_starter")
|
tasks_starter_thread = Thread(target=tasks_starter, name="tasks_starter")
|
||||||
tasks_starter_thread.start()
|
|
||||||
|
|
||||||
def internet_check():
|
def internet_check():
|
||||||
logger.info("Checking Internet. This may take a minute.")
|
logger.info("Checking Internet. This may take a minute.")
|
||||||
Console.info("\nChecking Internet. This may take a minute.")
|
Console.info("Checking Internet. This may take a minute.")
|
||||||
|
|
||||||
if not helper.check_internet():
|
if not helper.check_internet():
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -190,37 +185,56 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
|
|
||||||
internet_check_thread = Thread(target=internet_check, name="internet_check")
|
internet_check_thread = Thread(target=internet_check, name="internet_check")
|
||||||
internet_check_thread.start()
|
|
||||||
|
|
||||||
if not controller.check_system_user():
|
def controller_setup():
|
||||||
controller.add_system_user()
|
if not controller.check_system_user():
|
||||||
|
controller.add_system_user()
|
||||||
|
|
||||||
Crafty = MainPrompt(helper, tasks_manager, migration_manager, controller)
|
project_root = os.path.dirname(__file__)
|
||||||
|
controller.set_project_root(project_root)
|
||||||
|
controller.clear_unexecuted_commands()
|
||||||
|
controller.clear_support_status()
|
||||||
|
|
||||||
project_root = os.path.dirname(__file__)
|
crafty_prompt = MainPrompt(helper, tasks_manager, migration_manager, controller)
|
||||||
controller.set_project_root(project_root)
|
|
||||||
controller.clear_unexecuted_commands()
|
controller_setup_thread = Thread(target=controller_setup, name="controller_setup")
|
||||||
controller.clear_support_status()
|
|
||||||
|
def setup_starter():
|
||||||
|
if not args.daemon:
|
||||||
|
time.sleep(0.01) # Wait for the prompt to start
|
||||||
|
print() # Make a newline after the prompt so logs are on an empty line
|
||||||
|
else:
|
||||||
|
time.sleep(0.01) # Wait for the daemon info message
|
||||||
|
|
||||||
|
Console.info("Setting up Crafty's internal components...")
|
||||||
|
|
||||||
|
# Start the setup threads
|
||||||
|
tasks_starter_thread.start()
|
||||||
|
internet_check_thread.start()
|
||||||
|
controller_setup_thread.start()
|
||||||
|
|
||||||
|
# Wait for the setup threads to finish
|
||||||
|
tasks_starter_thread.join()
|
||||||
|
internet_check_thread.join()
|
||||||
|
controller_setup_thread.join()
|
||||||
|
|
||||||
|
Console.info("Crafty has fully started and is now ready for use!")
|
||||||
|
|
||||||
|
if not args.daemon:
|
||||||
|
# Put the prompt under the cursor
|
||||||
|
crafty_prompt.print_prompt()
|
||||||
|
|
||||||
|
Thread(target=setup_starter, name="setup_starter").start()
|
||||||
|
|
||||||
if not args.daemon:
|
if not args.daemon:
|
||||||
try:
|
# Start the Crafty prompt
|
||||||
Crafty.cmdloop()
|
crafty_prompt.cmdloop()
|
||||||
except KeyboardInterrupt:
|
|
||||||
print() # for newline
|
|
||||||
logger.info("Recieved SIGINT, stopping Crafty...")
|
|
||||||
Console.info("Recieved SIGINT, stopping Crafty...")
|
|
||||||
tasks_manager._main_graceful_exit()
|
|
||||||
Crafty.universal_exit()
|
|
||||||
else:
|
else:
|
||||||
print("Crafty started in daemon mode, no shell will be printed")
|
Console.info("Crafty started in daemon mode, no shell will be printed")
|
||||||
|
print()
|
||||||
while True:
|
while True:
|
||||||
try:
|
if tasks_manager.get_main_thread_run_status():
|
||||||
if tasks_manager.get_main_thread_run_status():
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
logger.info("Recieved SIGINT, stopping Crafty...")
|
|
||||||
Console.info("Recieved SIGINT, stopping Crafty...")
|
|
||||||
break
|
break
|
||||||
|
time.sleep(1)
|
||||||
tasks_manager._main_graceful_exit()
|
tasks_manager._main_graceful_exit()
|
||||||
Crafty.universal_exit()
|
crafty_prompt.universal_exit()
|
||||||
|
Loading…
Reference in New Issue
Block a user