From 16f59b1c408dbff4781ad7ccfa70e81d6d98f7bd Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Tue, 25 Mar 2025 23:06:57 +0100 Subject: [PATCH] feat(goose): optimize init status --- mcontainer/drivers/goose/init-status.sh | 78 +++++++------------------ 1 file changed, 21 insertions(+), 57 deletions(-) diff --git a/mcontainer/drivers/goose/init-status.sh b/mcontainer/drivers/goose/init-status.sh index 993a2b7..b5ae04a 100644 --- a/mcontainer/drivers/goose/init-status.sh +++ b/mcontainer/drivers/goose/init-status.sh @@ -1,65 +1,29 @@ #!/bin/bash -# Script to check and display initialization status +# Script to check and display initialization status - optimized version -# Function to display initialization logs -show_init_logs() { +# Quick check instead of full logic +if grep -q "INIT_COMPLETE=true" "/init.status" 2>/dev/null; then + echo "MC initialization has completed." +else + echo "MC initialization is still in progress." + # Only follow logs if initialization is incomplete if [ -f "/init.log" ]; then - echo "Displaying initialization logs:" - echo "----------------------------------------" - cat /init.log + echo "Initialization is still in progress. Showing logs:" echo "----------------------------------------" + tail -f /init.log & + tail_pid=$! + + # Check every second if initialization has completed + while true; do + if grep -q "INIT_COMPLETE=true" "/init.status" 2>/dev/null; then + kill $tail_pid 2>/dev/null + echo "----------------------------------------" + echo "Initialization completed." + break + fi + sleep 1 + done else echo "No initialization logs found." fi -} - -# Function to follow logs until initialization completes -follow_init_logs() { - if [ ! -f "/init.log" ]; then - echo "No initialization logs found." - return - fi - - echo "Initialization is still in progress. Showing logs:" - echo "----------------------------------------" - tail -f /init.log & - tail_pid=$! - - # Check every second if initialization has completed - while true; do - if [ -f "/init.status" ] && grep -q "INIT_COMPLETE=true" "/init.status"; then - kill $tail_pid 2>/dev/null - echo "----------------------------------------" - echo "Initialization completed." - break - fi - sleep 1 - done -} - -# Check if we're in an interactive shell -if [ -t 0 ]; then - INTERACTIVE=true -else - INTERACTIVE=false -fi - -# Check initialization status -if [ -f "/init.status" ]; then - if grep -q "INIT_COMPLETE=true" "/init.status"; then - echo "MC initialization has completed." - # No longer prompt to show logs when initialization is complete - else - echo "MC initialization is still in progress." - follow_init_logs - fi -else - echo "Cannot determine initialization status." - # Ask if user wants to see logs if they exist (only in interactive mode) - if [ -f "/init.log" ] && [ "$INTERACTIVE" = true ]; then - read -p "Do you want to see initialization logs? (y/n): " show_logs - if [[ "$show_logs" =~ ^[Yy] ]]; then - show_init_logs - fi - fi fi \ No newline at end of file