#!/bin/bash # Define the log file path PLAYIT_LOG_FILE="${MINECRAFT_SERVER_DIR}/playit_error.log" # --- CRITICAL TROUBLESHOOTING: Binary Check & Immediate Failure Capture --- echo "==================================================" > "$PLAYIT_LOG_FILE" echo "STARTING PLAYIT AGENT DIAGNOSTICS" >> "$PLAYIT_LOG_FILE" echo "--------------------------------------------------" >> "$PLAYIT_LOG_FILE" # 1. Use 'file' command to check if the binary is valid echo "1. Checking binary file type..." >> "$PLAYIT_LOG_FILE" file /usr/local/bin/playit >> "$PLAYIT_LOG_FILE" 2>&1 # 2. Check execution permissions echo "2. Checking permissions and ownership..." >> "$PLAYIT_LOG_FILE" ls -l /usr/local/bin/playit >> "$PLAYIT_LOG_FILE" 2>&1 # 3. CRITICAL: Try running a minimal command and capture the exit code echo "3. Testing basic execution and exit code..." >> "$PLAYIT_LOG_FILE" # Run with exec to capture any immediate low-level crash (e.g., missing library) /usr/local/bin/playit --version > /dev/null 2>&1 EXEC_STATUS=$? echo "Exit Status of 'playit --version': $EXEC_STATUS" >> "$PLAYIT_LOG_FILE" if [ "$EXEC_STATUS" -ne 0 ]; then echo "--------------------------------------------------" >> "$PLAYIT_LOG_FILE" echo "FATAL: PlayIt binary failed to execute (Exit Code: $EXEC_STATUS)." >> "$PLAYIT_LOG_FILE" echo "This indicates a corrupted file, missing shared library, or wrong architecture." >> "$PLAYIT_LOG_FILE" echo "PlayIt setup aborted." >> "$PLAYIT_LOG_FILE" echo "--------------------------------------------------" >> "$PLAYIT_LOG_FILE" fi # --- End Troubleshooting --- # --- 1. Start PlayIt.gg Agent in the background --- if [ -z "$PLAYIT_SECRET_KEY" ]; then echo "WARNING: PLAYIT_SECRET_KEY is not set. PlayIt tunnel will not start." >> "$PLAYIT_LOG_FILE" elif [ "$EXEC_STATUS" -eq 0 ]; then # Only proceed if the basic execution test passed echo "Starting PlayIt.gg Agent with 'run' command..." >> "$PLAYIT_LOG_FILE" /usr/local/bin/playit run --secret-key "$PLAYIT_SECRET_KEY" --api-address 127.0.0.1:9000 >> "$PLAYIT_LOG_FILE" 2>&1 & # Wait for tunnel establishment for i in {1..30}; do if grep -q ".playit.gg" "$PLAYIT_LOG_FILE"; then echo "PlayIt.gg tunnel address found! Logs are now complete." >> "$PLAYIT_LOG_FILE" break fi sleep 1 done fi # --- 2. Display the PlayIt Tunnel Address (in the main console) --- echo "==================================================" echo "PLAYIT.GG LOGS (Tunnel Address):" if [ -f "$PLAYIT_LOG_FILE" ]; then # Print the full log contents for immediate diagnosis cat "$PLAYIT_LOG_FILE" else echo "PlayIt.gg Agent log file was never created." fi echo "==================================================" # --- 3. Start the main Python Application (Flask + Minecraft) --- echo "Starting main Python application (app.py)..." exec python app.py