From 19f2d98386aa8cd94c778a03e02df3b8388fba19 Mon Sep 17 00:00:00 2001 From: "Tomi P. Hakala" Date: Sat, 28 Dec 2024 18:25:15 +0200 Subject: [PATCH] fix: improve BirdNET-Go service startup and container initialization in install script - Enhanced the service startup check to provide clearer feedback on success or failure. - Implemented a retry mechanism for waiting on the Docker container to start, with a maximum of 30 attempts. - Updated the overlap settings for Raspberry Pi models to optimize performance. --- install.sh | 58 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 401f965..24a4b54 100755 --- a/install.sh +++ b/install.sh @@ -918,26 +918,48 @@ check_existing_containers() { start_birdnet_go() { print_message "\nšŸš€ Starting BirdNET-Go..." "$GREEN" sudo systemctl start birdnet-go.service - # check status - if sudo systemctl is-active --quiet birdnet-go.service; then - print_message "āœ… BirdNET-Go started successfully!" "$GREEN" - print_message "\nšŸ³ Checking container logs..." "$YELLOW" - # Wait a moment for the container to start - sleep 2 - # Get container ID and show logs + + # Check if service started + if ! sudo systemctl is-active --quiet birdnet-go.service; then + print_message "āŒ Failed to start BirdNET-Go service" "$RED" + exit 1 + fi + print_message "āœ… BirdNET-Go service started successfully!" "$GREEN" + + print_message "\nšŸ³ Waiting for container to start..." "$YELLOW" + + # Wait for container to appear and be running (max 30 seconds) + local max_attempts=30 + local attempt=1 + local container_id="" + + while [ $attempt -le $max_attempts ]; do container_id=$(docker ps --filter "ancestor=${BIRDNET_GO_IMAGE}" --format "{{.ID}}") if [ -n "$container_id" ]; then - docker logs "$container_id" - print_message "\nTo follow logs in real-time, use:" "$YELLOW" - print_message "docker logs -f $container_id" "$NC" - else - print_message "āŒ Container not found. Please check 'docker ps' output." "$RED" - exit 1 + print_message "āœ… Container started successfully!" "$GREEN" + break fi - else - print_message "āŒ Failed to start BirdNET-Go. Please check the logs for errors." "$RED" + print_message "ā³ Waiting for container to start (attempt $attempt/$max_attempts)..." "$YELLOW" + sleep 1 + ((attempt++)) + done + + if [ -z "$container_id" ]; then + print_message "āŒ Container failed to start within ${max_attempts} seconds" "$RED" + print_message "Please check 'docker ps' and 'journalctl -u birdnet-go' for errors" "$YELLOW" exit 1 fi + + # Wait additional time for application to initialize + print_message "ā³ Waiting for application to initialize..." "$YELLOW" + sleep 5 + + # Show logs + print_message "\nšŸ“ Container logs:" "$GREEN" + docker logs "$container_id" + + print_message "\nTo follow logs in real-time, use:" "$YELLOW" + print_message "docker logs -f $container_id" "$NC" } # Function to detect Raspberry Pi model @@ -991,17 +1013,17 @@ optimize_settings() { ;; 4) # RPi 4 settings - sed -i 's/overlap: 1.5/overlap: 2.7/' "$CONFIG_FILE" + sed -i 's/overlap: 1.5/overlap: 2.6/' "$CONFIG_FILE" print_message "āœ… Applied optimized settings for Raspberry Pi 4" "$GREEN" ;; 3) # RPi 3 settings - sed -i 's/overlap: 1.5/overlap: 2.5/' "$CONFIG_FILE" + sed -i 's/overlap: 1.5/overlap: 2.0/' "$CONFIG_FILE" print_message "āœ… Applied optimized settings for Raspberry Pi 3" "$GREEN" ;; 2) # RPi Zero 2 settings - sed -i 's/overlap: 1.5/overlap: 2.5/' "$CONFIG_FILE" + sed -i 's/overlap: 1.5/overlap: 2.0/' "$CONFIG_FILE" print_message "āœ… Applied optimized settings for Raspberry Pi Zero 2" "$GREEN" ;; esac