Files
labFusion/runners/fix-cache-issues.sh
GSRN 8c9ffb50ce fix: Resolve mvn command not found error in CI workflow
- Replace 'mvn' commands with './mvnw' in CI workflow
- Add chmod +x ./mvnw step to make Maven wrapper executable
- Add cache: maven to Java setup step for better caching
- Update troubleshooting scripts to use correct port 40047
- Update documentation to reflect port change

This fixes the 'mvn: command not found' error by ensuring
all Maven commands use the Maven wrapper (mvnw) which is
included in the project and doesn't require Maven to be
pre-installed on the runner.
2025-09-15 17:16:13 +02:00

203 lines
5.5 KiB
Bash

#!/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}:40047/"
export ACTIONS_RUNTIME_URL="http://${HOST_IP}:40047/"
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_IP}:40047/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 "$@"