Add port availability check to setup scripts

Before starting Docker containers, setup scripts now check if required
ports are available and warn users about conflicts.

Features:
- Checks all required ports: 8080, 8025, 1025, 6379
- Checks database port based on selection (3306 for MySQL, 5432 for PostgreSQL)
- Shows clear status for each port (Available/In Use)
- If conflicts found:
  - Displays warning message
  - Shows helpful commands to find and stop conflicting processes
  - Asks user if they want to continue anyway
  - Exits if user chooses not to continue

Benefits:
- Prevents confusing 'port already in use' errors during container startup
- Provides clear diagnostic information
- Gives users control over how to handle conflicts
- Improves setup experience and reduces frustration

Implementation:
- setup.bat: Uses netstat with findstr for Windows
- setup.sh: Uses lsof and netstat for Linux/Mac compatibility
This commit is contained in:
2026-03-10 11:56:25 +02:00
parent 83131d8432
commit e7fcaa35e1
2 changed files with 153 additions and 17 deletions

101
setup.bat
View File

@@ -24,7 +24,90 @@ echo.
echo Setting up with %DB%...
echo.
REM Step 1: Configure environment
REM Step 1: Check port availability
echo Checking port availability...
set PORTS_OK=1
REM Check port 8080 (Nginx)
netstat -ano | findstr ":8080 " | findstr "LISTENING" >nul 2>&1
if %errorlevel% equ 0 (
echo [X] Port 8080 (Web Server) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 8080 (Web Server) - Available
)
REM Check port 8025 (Mailpit Dashboard)
netstat -ano | findstr ":8025 " | findstr "LISTENING" >nul 2>&1
if %errorlevel% equ 0 (
echo [X] Port 8025 (Mailpit Dashboard) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 8025 (Mailpit Dashboard) - Available
)
REM Check port 1025 (Mailpit SMTP)
netstat -ano | findstr ":1025 " | findstr "LISTENING" >nul 2>&1
if %errorlevel% equ 0 (
echo [X] Port 1025 (Mailpit SMTP) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 1025 (Mailpit SMTP) - Available
)
REM Check port 6379 (Redis)
netstat -ano | findstr ":6379 " | findstr "LISTENING" >nul 2>&1
if %errorlevel% equ 0 (
echo [X] Port 6379 (Redis) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 6379 (Redis) - Available
)
REM Check database port based on selection
if "%DB%"=="mysql" (
netstat -ano | findstr ":3306 " | findstr "LISTENING" >nul 2>&1
if !errorlevel! equ 0 (
echo [X] Port 3306 (MySQL) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 3306 (MySQL) - Available
)
)
if "%DB%"=="pgsql" (
netstat -ano | findstr ":5432 " | findstr "LISTENING" >nul 2>&1
if !errorlevel! equ 0 (
echo [X] Port 5432 (PostgreSQL) - IN USE
set PORTS_OK=0
) else (
echo [√] Port 5432 (PostgreSQL) - Available
)
)
REM Handle port conflicts
if %PORTS_OK% equ 0 (
echo.
echo WARNING: Some required ports are already in use!
echo.
echo To find what's using a port:
echo netstat -ano ^| findstr ":PORT"
echo.
echo To stop a process using a port:
echo 1. Find the PID from netstat output
echo 2. taskkill /PID [PID] /F
echo.
choice /C YN /M "Do you want to continue anyway"
if errorlevel 2 (
echo Setup cancelled.
exit /b 1
)
echo.
echo Continuing with setup...
)
echo.
REM Step 2: Configure environment
echo Configuring environment...
if exist "src\.env.%DB%" (
copy /y "src\.env.%DB%" "src\.env" >nul
@@ -34,25 +117,25 @@ if exist "src\.env.%DB%" (
exit /b 1
)
REM Step 2: Build containers
REM Step 3: Build containers
echo Building Docker containers...
docker-compose build
echo Containers built
echo.
REM Step 3: Start containers
REM Step 4: Start containers
echo Starting Docker containers...
docker-compose --profile %DB% up -d
echo Containers started
echo.
REM Step 4: Wait for app container to be ready
REM Step 5: Wait for app container to be ready
echo Waiting for app container...
timeout /t 3 /nobreak >nul
echo App container ready
echo.
REM Step 5: Wait for database
REM Step 6: Wait for database
if "%DB%"=="mysql" (
echo Waiting for database...
timeout /t 5 /nobreak >nul
@@ -66,25 +149,25 @@ if "%DB%"=="pgsql" (
echo.
)
REM Step 6: Generate app key
REM Step 7: Generate app key
echo Generating application key...
docker-compose exec -T app php artisan key:generate --force
echo App key generated
echo.
REM Step 7: Run migrations
REM Step 8: Run migrations
echo Running database migrations...
docker-compose exec -T app php artisan migrate --force
echo Migrations completed
echo.
REM Step 8: Seed database
REM Step 9: Seed database
echo Seeding database (roles, permissions, admin user)...
docker-compose exec -T app php artisan db:seed --force
echo Database seeded
echo.
REM Step 9: Create storage link
REM Step 10: Create storage link
echo Creating storage symlink...
docker-compose exec -T app php artisan storage:link
echo Storage linked