#!/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 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" # Set proper environment variables export ACTIONS_CACHE_URL="http://host.docker.internal:44029/" export ACTIONS_RUNTIME_URL="http://host.docker.internal:44029/" echo "โœ… Cache directory created and configured" echo "โœ… Environment variables set" } # Function to restart cache service restart_cache_service() { echo "๐Ÿ”„ Restarting cache service..." # Stop existing runners pkill -f "act_runner" || true sleep 2 # Start with fixed configuration if [ -f "config_cache_fixed.yaml" ]; then echo "โœ… Using fixed configuration" nohup ./act_runner daemon --config config_cache_fixed.yaml > runner.log 2>&1 & else echo "โš ๏ธ Fixed 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 "$@"