FlexGate Installation Troubleshooting Guide
Overview
This guide covers common installation failures, how to diagnose them, and recovery procedures.
Table of Contents
- Pre-Installation Checks
- Common Installation Failures
- Database Issues
- Redis Issues
- Container/Podman Issues
- Admin UI Build Failures
- Network & Port Conflicts
- Recovery Procedures
- Rollback & Clean Restart
- Health Check Scripts
Pre-Installation Checks
System Requirements Check Script
#!/bin/bash
# check-requirements.sh
echo "🔍 Checking FlexGate Requirements..."
echo ""
# Check Node.js
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v)
echo "✅ Node.js installed: $NODE_VERSION"
# Check if version >= 16
MAJOR_VERSION=$(echo $NODE_VERSION | cut -d'v' -f2 | cut -d'.' -f1)
if [ $MAJOR_VERSION -lt 16 ]; then
echo "❌ Node.js version must be >= 16.x"
exit 1
fi
else
echo "❌ Node.js not installed"
echo " Install from: https://nodejs.org/"
exit 1
fi
# Check npm
if command -v npm &> /dev/null; then
NPM_VERSION=$(npm -v)
echo "✅ npm installed: $NPM_VERSION"
else
echo "❌ npm not installed"
exit 1
fi
# Check Podman or Docker
if command -v podman &> /dev/null; then
PODMAN_VERSION=$(podman -v)
echo "✅ Podman installed: $PODMAN_VERSION"
elif command -v docker &> /dev/null; then
DOCKER_VERSION=$(docker -v)
echo "✅ Docker installed: $DOCKER_VERSION"
else
echo "⚠️ Neither Podman nor Docker installed"
echo " Required for Standard/Production modes"
echo " Simple mode will still work"
fi
# Check available ports
echo ""
echo "🔍 Checking port availability..."
check_port() {
if lsof -Pi :$1 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "❌ Port $1 already in use"
lsof -i :$1 | grep LISTEN
return 1
else
echo "✅ Port $1 available"
return 0
fi
}
check_port 3000 # FlexGate backend
check_port 3001 # Admin UI / Grafana
check_port 5432 # PostgreSQL
check_port 6379 # Redis
check_port 8080 # HAProxy
check_port 9090 # Prometheus
# Check disk space
echo ""
echo "🔍 Checking disk space..."
AVAILABLE_SPACE=$(df -h . | awk 'NR==2 {print $4}')
echo "Available disk space: $AVAILABLE_SPACE"
# Check memory
echo ""
echo "🔍 Checking available memory..."
if [[ "$OSTYPE" == "darwin"* ]]; then
MEMORY=$(sysctl hw.memsize | awk '{print $2/1024/1024/1024 " GB"}')
echo "Total memory: $MEMORY"
elif [[ "$OSTYPE" == "linux"* ]]; then
MEMORY=$(free -h | awk '/^Mem:/ {print $2}')
echo "Total memory: $MEMORY"
fi
echo ""
echo "✅ Pre-installation checks complete!"Usage:
chmod +x check-requirements.sh
./check-requirements.shCommon Installation Failures
1. npm install Failures
Error: EACCES permission denied
Problem:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13Solution:
# Option 1: Fix npm permissions (recommended)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
# Option 2: Use npx (no global install)
npx flexgate-proxy init
# Option 3: Use sudo (not recommended)
sudo npm install -g flexgate-proxyError: Network timeout
Problem:
npm ERR! network request to https://registry.npmjs.org/flexgate-proxy failed
npm ERR! network This is a problem related to network connectivitySolution:
# 1. Check internet connection
ping registry.npmjs.org
# 2. Clear npm cache
npm cache clean --force
# 3. Use different registry
npm config set registry https://registry.npmjs.org/
# 4. Increase timeout
npm install flexgate-proxy --timeout=60000
# 5. Try yarn instead
yarn add flexgate-proxyError: Incompatible dependencies
Problem:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency treeSolution:
# Option 1: Use --legacy-peer-deps
npm install flexgate-proxy --legacy-peer-deps
# Option 2: Use --force (last resort)
npm install flexgate-proxy --force
# Option 3: Clean install
rm -rf node_modules package-lock.json
npm install
# Option 4: Check Node.js version
node -v # Should be >= 16.x
nvm use 18 # If using nvm2. Build Failures
TypeScript Compilation Errors
Problem:
error TS2307: Cannot find module '@types/node'Solution:
# Install missing types
npm install --save-dev @types/node @types/express
# Clean build
rm -rf dist
npm run build
# If still failing, check tsconfig.json
cat tsconfig.jsonAdmin UI Build Failures
Problem:
Creating an optimized production build...
Failed to compile.Solution:
cd admin-ui
# Check for errors
npm run build 2>&1 | tee build.log
# Clear cache
rm -rf node_modules/.cache
rm -rf build
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
# Try build again
npm run build
# If memory issues
NODE_OPTIONS="--max-old-space-size=4096" npm run buildDatabase Issues
PostgreSQL Connection Failed
Error: Connection refused
Problem:
Error: connect ECONNREFUSED 127.0.0.1:5432Diagnosis:
# Check if PostgreSQL container is running
podman ps | grep postgres
# Check PostgreSQL logs
podman logs flexgate-postgres
# Try connecting manually
psql -h localhost -U flexgate -d flexgateSolutions:
Solution 1: Container not started
# Start PostgreSQL
npm run db:start
# Wait for ready
sleep 5
# Check status
podman ps | grep postgresSolution 2: Wrong credentials
# Check .env file
cat .env | grep DATABASE
# Update if needed
DATABASE_URL=postgresql://flexgate:flexgate@localhost:5432/flexgateSolution 3: Port conflict
# Check what's using port 5432
lsof -i :5432
# Kill conflicting process
kill -9 <PID>
# Or use different port
podman-compose -f podman-compose.dev.yml down
# Edit podman-compose.dev.yml: "5433:5432"
podman-compose -f podman-compose.dev.yml up -dSolution 4: Container unhealthy
# Check container health
podman inspect flexgate-postgres | grep -A 10 Health
# Restart container
podman restart flexgate-postgres
# Or recreate
podman-compose -f podman-compose.dev.yml down -v
podman-compose -f podman-compose.dev.yml up -dMigration Failures
Problem:
Error: relation "routes" already existsSolution:
# Check migration status
npm run db:migrate -- --status
# Reset database (WARNING: loses data)
npm run db:reset
# Or manually fix
psql -h localhost -U flexgate -d flexgate -c "DROP TABLE IF EXISTS routes CASCADE;"
npm run db:migrateSchema Corruption
Problem:
Error: column "created_at" does not existRecovery:
# Backup existing data (if any)
podman exec flexgate-postgres pg_dump -U flexgate flexgate > backup.sql
# Reset database
npm run db:reset
# Or drop and recreate
psql -h localhost -U flexgate -d flexgate -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
npm run db:migrate
# Restore data if needed
psql -h localhost -U flexgate flexgate < backup.sqlRedis Issues
Redis Connection Failed
Problem:
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSEDDiagnosis:
# Check if Redis is running
podman ps | grep redis
# Check Redis logs
podman logs flexgate-redis
# Test connection
redis-cli -h localhost -p 6379 pingSolutions:
Solution 1: Start Redis
npm run db:start
# OR
podman-compose -f podman-compose.dev.yml up -d redisSolution 2: Port conflict
# Check port 6379
lsof -i :6379
# Kill process or use different port
# Edit podman-compose.dev.yml: "6380:6379"
# Update .env: REDIS_URL=redis://localhost:6380Solution 3: Redis crashed
# Check logs
podman logs flexgate-redis --tail=50
# Restart
podman restart flexgate-redis
# If corrupt data
podman exec flexgate-redis redis-cli FLUSHALLContainer/Podman Issues
Podman Not Found
Problem:
npm run podman:run
podman: command not foundSolution:
# macOS
brew install podman
podman machine init
podman machine start
# Linux
sudo apt-get install podman # Debian/Ubuntu
sudo dnf install podman # Fedora/RHEL
# Verify
podman --versionImage Build Failures
Problem:
npm run podman:build
Error: error building at STEP "RUN npm ci"Solutions:
Solution 1: Network issues
# Build with retry
podman build -t localhost/flexgate-proxy:latest . --retry=3
# Use BuildKit cache
podman build --no-cache -t localhost/flexgate-proxy:latest .Solution 2: Insufficient resources
# Increase Podman machine resources (macOS)
podman machine stop
podman machine set --memory=4096 --cpus=4
podman machine start
# Check available space
df -hSolution 3: Dependency issues
# Update Dockerfile with --legacy-peer-deps
# Edit Dockerfile:
# RUN npm ci --only=production --legacy-peer-deps
podman build -t localhost/flexgate-proxy:latest .Container Won't Start
Problem:
npm run podman:run
Error: container died unexpectedlyDiagnosis:
# Check container logs
podman logs flexgate-app-1
# Check container status
podman ps -a | grep flexgate
# Inspect container
podman inspect flexgate-app-1Solutions:
Solution 1: Port conflict
# Check what's using ports
lsof -i :3000
lsof -i :8080
# Kill processes
kill -9 <PID>
# Or edit port mapping in podman-compose.ymlSolution 2: Missing environment variables
# Check .env file exists
cat .env
# Create if missing
cat > .env << EOF
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://flexgate:flexgate@postgres:5432/flexgate
REDIS_URL=redis://redis:6379
EOFSolution 3: Database not ready
# Ensure database starts first
podman-compose up -d postgres redis
sleep 5
podman-compose up -d flexgate-app-1 flexgate-app-2Admin UI Build Failures
React Build Errors
Problem:
cd admin-ui && npm run build
Failed to compile.Solutions:
Solution 1: Clear cache
cd admin-ui
rm -rf node_modules/.cache
rm -rf build
npm cache clean --force
npm install
npm run buildSolution 2: Memory issues
# Increase Node.js memory
NODE_OPTIONS="--max-old-space-size=4096" npm run buildSolution 3: Dependency issues
cd admin-ui
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps
npm run buildTypeScript Type Errors
Problem:
Type error: Property 'item' does not exist on type...Solution:
# Update @mui/material types
cd admin-ui
npm install --save-dev @types/react@latest @mui/material@latest
# Or skip type checking in build
SKIP_PREFLIGHT_CHECK=true npm run build
# Or update tsconfig.json to be more lenientNetwork & Port Conflicts
Port Already in Use
Problem:
Error: listen EADDRINUSE: address already in use :::3000Solutions:
Solution 1: Kill process
# Find process using port 3000
lsof -ti:3000
# Kill it
kill -9 $(lsof -ti:3000)
# Or use different port
PORT=3001 npm startSolution 2: Change default ports
# Edit .env
PORT=3100
# For containers, edit podman-compose.yml
# ports:
# - "3100:3000"Proxy Configuration Issues
Problem:
Admin UI can't connect to backend APISolutions:
Solution 1: Check proxy config
# admin-ui/package.json should have:
{
"proxy": "http://localhost:3000"
}Solution 2: CORS errors
# Update FlexGate CORS settings
# Via Admin UI: Settings → Security → CORS
# Or in .env:
CORS_ORIGIN=http://localhost:3001Recovery Procedures
Complete Clean Install
#!/bin/bash
# clean-install.sh
echo "🧹 Starting clean FlexGate installation..."
# 1. Stop all services
echo "Stopping services..."
npm run podman:stop 2>/dev/null || true
npm run db:stop 2>/dev/null || true
# 2. Remove containers and volumes
echo "Removing containers and volumes..."
podman-compose -f podman-compose.yml down -v 2>/dev/null || true
podman-compose -f podman-compose.dev.yml down -v 2>/dev/null || true
# 3. Remove node_modules
echo "Cleaning dependencies..."
rm -rf node_modules
rm -rf admin-ui/node_modules
rm -rf package-lock.json
rm -rf admin-ui/package-lock.json
# 4. Clean build artifacts
echo "Cleaning build artifacts..."
rm -rf dist
rm -rf admin-ui/build
rm -rf admin-ui/.cache
# 5. Reinstall dependencies
echo "Installing dependencies..."
npm install
cd admin-ui
npm install
cd ..
# 6. Build FlexGate
echo "Building FlexGate..."
npm run build
# 7. Build Admin UI
echo "Building Admin UI..."
cd admin-ui
npm run build
cd ..
# 8. Start services
echo "Starting services..."
npm run db:start
sleep 5
# 9. Run migrations
echo "Running migrations..."
npm run db:migrate
# 10. Start FlexGate
echo "Starting FlexGate..."
npm start &
echo ""
echo "✅ Clean installation complete!"
echo "🌐 FlexGate: http://localhost:3000"
echo "🎨 Admin UI: http://localhost:8080/admin"Partial Recovery (Keep Data)
#!/bin/bash
# partial-recovery.sh
echo "🔧 Starting partial recovery..."
# Keep database volumes, just restart services
# 1. Stop FlexGate
echo "Stopping FlexGate..."
pkill -f "node.*flexgate"
podman stop flexgate-app-1 flexgate-app-2 2>/dev/null || true
# 2. Keep database running, just check health
echo "Checking database..."
if ! podman ps | grep -q flexgate-postgres; then
echo "Starting PostgreSQL..."
podman-compose -f podman-compose.dev.yml up -d postgres
sleep 3
fi
if ! podman ps | grep -q flexgate-redis; then
echo "Starting Redis..."
podman-compose -f podman-compose.dev.yml up -d redis
sleep 2
fi
# 3. Rebuild only what's needed
echo "Rebuilding..."
npm run build
# 4. Restart FlexGate
echo "Restarting FlexGate..."
npm start
echo "✅ Partial recovery complete!"Rollback & Clean Restart
Version Rollback
# If new version breaks, rollback to previous
# 1. Check npm version history
npm view flexgate-proxy versions
# 2. Install specific version
npm install flexgate-proxy@0.1.0-beta.1
# 3. Or use git tags
git checkout v0.1.0-beta.1
npm install
npm run build
npm startDatabase Rollback
# Rollback to previous migration
# 1. Check current version
npm run db:migrate -- --status
# 2. Rollback one migration
npm run db:migrate -- --down
# 3. Or reset completely
npm run db:resetHealth Check Scripts
Automated Health Check
#!/bin/bash
# health-check.sh
echo "🏥 Running FlexGate health checks..."
FAILED=0
# Check FlexGate API
echo "Checking FlexGate API..."
if curl -sf http://localhost:3000/health > /dev/null; then
echo "✅ FlexGate API: healthy"
else
echo "❌ FlexGate API: failed"
FAILED=1
fi
# Check PostgreSQL
echo "Checking PostgreSQL..."
if podman exec flexgate-postgres pg_isready -U flexgate > /dev/null 2>&1; then
echo "✅ PostgreSQL: healthy"
else
echo "❌ PostgreSQL: failed"
FAILED=1
fi
# Check Redis
echo "Checking Redis..."
if podman exec flexgate-redis redis-cli ping > /dev/null 2>&1; then
echo "✅ Redis: healthy"
else
echo "❌ Redis: failed"
FAILED=1
fi
# Check Admin UI (if built)
if [ -d "admin-ui/build" ]; then
echo "✅ Admin UI: built"
else
echo "⚠️ Admin UI: not built (run: cd admin-ui && npm run build)"
fi
# Summary
echo ""
if [ $FAILED -eq 0 ]; then
echo "✅ All health checks passed!"
exit 0
else
echo "❌ Some health checks failed!"
echo "Run: npm run db:start"
exit 1
fiAuto-Recovery Script
#!/bin/bash
# auto-recover.sh
echo "🔧 Attempting auto-recovery..."
# Check what's failing and try to fix
# 1. Check if PostgreSQL is down
if ! podman ps | grep -q flexgate-postgres; then
echo "PostgreSQL down, restarting..."
podman-compose -f podman-compose.dev.yml up -d postgres
sleep 5
fi
# 2. Check if Redis is down
if ! podman ps | grep -q flexgate-redis; then
echo "Redis down, restarting..."
podman-compose -f podman-compose.dev.yml up -d redis
sleep 3
fi
# 3. Check if FlexGate is down
if ! curl -sf http://localhost:3000/health > /dev/null; then
echo "FlexGate down, restarting..."
pkill -f "node.*flexgate"
sleep 2
npm start &
sleep 5
fi
# 4. Run health check
./health-check.shEmergency Procedures
Total Reset (Nuclear Option)
#!/bin/bash
# nuclear-reset.sh
echo "☢️ WARNING: This will delete ALL data!"
read -p "Are you sure? (type 'yes' to continue): " confirm
if [ "$confirm" != "yes" ]; then
echo "Cancelled."
exit 0
fi
echo "Performing total reset..."
# Stop everything
podman stop $(podman ps -aq) 2>/dev/null || true
pkill -f node
# Remove all FlexGate containers and volumes
podman rm -f $(podman ps -aq --filter "name=flexgate") 2>/dev/null || true
podman volume rm $(podman volume ls -q --filter "name=flexgate") 2>/dev/null || true
# Remove all node_modules
find . -name "node_modules" -type d -prune -exec rm -rf {} \;
# Remove all build artifacts
rm -rf dist admin-ui/build
# Clean npm cache
npm cache clean --force
# Start fresh
echo "Ready for fresh install. Run: npm install"Logging & Debugging
Enable Debug Logging
# Enable verbose npm logs
npm install --loglevel verbose
# Enable FlexGate debug logs
DEBUG=flexgate:* npm start
# Enable all logs
DEBUG=* npm start
# Save logs to file
npm start 2>&1 | tee flexgate.logCheck System Logs
# Container logs
podman logs flexgate-app-1 --tail=100 -f
# Database logs
podman logs flexgate-postgres --tail=50
# All services
podman-compose -f podman-compose.yml logs -fSummary Checklist
When Installation Fails:
- ✅ Check pre-requirements (
./check-requirements.sh) - ✅ Check logs (npm, podman, console)
- ✅ Verify ports are available
- ✅ Check dependencies are installed
- ✅ Try clean install (
./clean-install.sh) - ✅ Check database is running
- ✅ Check Redis is running
- ✅ Run health checks (
./health-check.sh) - ✅ Check documentation for specific errors
- ✅ Seek help (GitHub Issues, Discord)
Quick Recovery Commands:
# Restart everything
npm run db:stop && npm run db:start && npm start
# Clean reinstall
rm -rf node_modules && npm install && npm run build
# Reset database
npm run db:reset
# Full reset
./nuclear-reset.sh # WARNING: deletes all dataGetting Help
Where to Get Support:
- GitHub Issues: https://github.com/tapas100/flexgate-proxy/issues
- Documentation:
/docs-site/folder - Discord: (community link)
- Stack Overflow: Tag
flexgate
Information to Include:
When reporting issues:
- OS and version
- Node.js version (
node -v) - npm version (
npm -v) - Podman/Docker version
- Full error logs
- Steps to reproduce
- What you've tried
All troubleshooting scripts are included in the repository! 🛠️