#!/bin/bash # Cache Troubleshooting and Fix Script for LabFusion CI/CD # This script helps diagnose and fix common cache timeout issues set -e echo "๐Ÿ”ง LabFusion Cache Troubleshooting Script" echo "==========================================" # Function to check if running in Docker check_docker() { if [ -f /.dockerenv ]; then echo "๐Ÿณ Running inside Docker container" return 0 else echo "๐Ÿ–ฅ๏ธ Running on host system" return 1 fi } # Function to check cache service status check_cache_service() { echo "๐Ÿ“Š Checking cache service status..." # Check if cache service is running if pgrep -f "act_runner" > /dev/null; then echo "โœ… act_runner process found" else echo "โŒ act_runner process not found" return 1 fi # Check cache directory CACHE_DIR="${HOME}/.cache/actcache" if [ -d "$CACHE_DIR" ]; then echo "โœ… Cache directory exists: $CACHE_DIR" echo " Size: $(du -sh "$CACHE_DIR" 2>/dev/null || echo "Unknown")" else echo "โš ๏ธ Cache directory not found: $CACHE_DIR" echo " Creating cache directory..." mkdir -p "$CACHE_DIR" fi } # Function to test network connectivity test_network() { echo "๐ŸŒ Testing network connectivity..." # Test basic connectivity if ping -c 1 8.8.8.8 > /dev/null 2>&1; then echo "โœ… Internet connectivity OK" else echo "โŒ Internet connectivity failed" fi # Test Docker daemon if docker info > /dev/null 2>&1; then echo "โœ… Docker daemon accessible" else echo "โŒ Docker daemon not accessible" fi } # Function to detect the correct host IP detect_host_ip() { echo "๐Ÿ” Detecting host IP address..." # Try different methods to get the host IP if command -v ip > /dev/null 2>&1; then # Linux with ip command HOST_IP=$(ip route get 1.1.1.1 | awk '{print $7; exit}' 2>/dev/null) elif command -v hostname > /dev/null 2>&1; then # Try hostname -I (Linux) HOST_IP=$(hostname -I | awk '{print $1}' 2>/dev/null) elif command -v ifconfig > /dev/null 2>&1; then # Try ifconfig (macOS/BSD) HOST_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1) else # Fallback to localhost HOST_IP="127.0.0.1" fi if [ -z "$HOST_IP" ] || [ "$HOST_IP" = "127.0.0.1" ]; then echo "โš ๏ธ Could not detect host IP, using localhost" HOST_IP="127.0.0.1" else echo "โœ… Detected host IP: $HOST_IP" fi echo "$HOST_IP" } # Function to fix common cache issues fix_cache_issues() { echo "๐Ÿ”ง Applying cache fixes..." # Create cache directory with proper permissions CACHE_DIR="${HOME}/.cache/actcache" mkdir -p "$CACHE_DIR" chmod 755 "$CACHE_DIR" # Detect host IP HOST_IP=$(detect_host_ip) # Set proper environment variables export ACTIONS_CACHE_URL="http://${HOST_IP}:44029/" export ACTIONS_RUNTIME_URL="http://${HOST_IP}:44029/" echo "โœ… Cache directory created and configured" echo "โœ… Environment variables set with host IP: $HOST_IP" } # Function to restart cache service restart_cache_service() { echo "๐Ÿ”„ Restarting cache service..." # Stop existing runners pkill -f "act_runner" || true sleep 2 # Start with updated configuration if [ -f "config_docker.yaml" ]; then echo "โœ… Using updated Docker configuration" nohup ./act_runner daemon --config config_docker.yaml > runner.log 2>&1 & elif [ -f "config_heavy.yaml" ]; then echo "โœ… Using updated heavy configuration" nohup ./act_runner daemon --config config_heavy.yaml > runner.log 2>&1 & else echo "โš ๏ธ Updated configuration not found, using default" nohup ./act_runner daemon > runner.log 2>&1 & fi sleep 5 if pgrep -f "act_runner" > /dev/null; then echo "โœ… Cache service restarted successfully" else echo "โŒ Failed to restart cache service" return 1 fi } # Function to test cache functionality test_cache() { echo "๐Ÿงช Testing cache functionality..." # Create a test cache entry TEST_KEY="test-cache-$(date +%s)" TEST_VALUE="test-value-$(date +%s)" echo " Creating test cache entry: $TEST_KEY" echo "$TEST_VALUE" > "/tmp/cache-test" # Try to restore (this will fail but we can check the error) echo " Testing cache restore..." if curl -s "http://host.docker.internal:44029/cache/$TEST_KEY" > /dev/null 2>&1; then echo "โœ… Cache service responding" else echo "โŒ Cache service not responding" echo " This is expected if no cache entry exists" fi # Clean up rm -f "/tmp/cache-test" } # Main execution main() { echo "Starting cache troubleshooting..." echo "" check_docker echo "" check_cache_service echo "" test_network echo "" fix_cache_issues echo "" restart_cache_service echo "" test_cache echo "" echo "๐ŸŽ‰ Cache troubleshooting complete!" echo "" echo "Next steps:" echo "1. Check runner logs: tail -f runner.log" echo "2. Test a workflow to see if cache issues are resolved" echo "3. If issues persist, check Docker networking configuration" echo "" echo "For more help, see: https://gitea.com/gitea/act_runner/src/branch/main/docs/configuration.md" } # Run main function main "$@"