first commit

This commit is contained in:
祀梦
2026-01-27 21:17:36 +08:00
commit b06044c91c
57 changed files with 6714 additions and 0 deletions

142
script/README.md Normal file
View File

@@ -0,0 +1,142 @@
# Proxy Pool Startup Scripts
## File List
- **start_backend.bat** - Start backend service
- **start_frontend.bat** - Start frontend service
- **stop_all.bat** - Stop all services
## Quick Start
### Start Services Separately
- Backend: Double-click `start_backend.bat`
- Frontend: Double-click `start_frontend.bat`
### Stop Services
Double-click `stop_all.bat` to stop all services
## Script Features
### Smart Process Management
- Automatically detect and stop running processes
- Prevent duplicate startup of multiple instances
- Automatically clean up port conflicts
### Log Management
- All output written to log files
- Backend log: `backend.log`
- Frontend log: `frontend.log`
- Logs include timestamps for troubleshooting
### PID Management
- Automatically record process ID to PID files
- Facilitates subsequent service stopping
- Automatically clean up PID files after process stops
### Port Cleanup
- Automatically detect and clean up port conflicts
- Backend port: 3000
- Frontend port: 8080
## Access Addresses
After successful startup:
- Backend API: http://localhost:3000
- Frontend UI: http://localhost:8080
## Manual Operations
### View Logs
```bash
# View backend log
type backend.log
# View frontend log
type frontend.log
```
### Manual Stop Process
```bash
# View PID file content
type backend.pid
type frontend.pid
# Stop process using PID
taskkill /F /PID <ProcessID>
```
### Check Port Usage
```bash
# Check backend port
netstat -ano | findstr :3000
# Check frontend port
netstat -ano | findstr :8080
```
## Log Examples
### backend.log
```
[13:30:15.00] ========================================
[13:30:15.00] Starting backend service...
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:3000
```
### frontend.log
```
[13:30:20.00] ========================================
[13:30:20.00] Starting frontend service...
VITE v5.0.0 ready in 1234 ms
➜ Local: http://localhost:8080/
➜ Network: use --host to expose
```
## Notes
1. **First-time frontend startup**: If dependencies are not installed, the script will automatically run `npm install`
2. **Virtual environment**: Ensure backend uses Python virtual environment (venv)
3. **Firewall**: Ensure firewall allows ports 3000 and 8080
4. **Antivirus**: Some antivirus software may block scripts, need to add to whitelist
## Troubleshooting
### Backend Won't Start
1. Check if Python virtual environment is correctly installed
2. View `backend.log` log file
3. Confirm port 3000 is not in use
4. Check if dependency packages are complete: `venv\Scripts\pip list`
### Frontend Won't Start
1. Check if Node.js is installed: `node --version`
2. View `frontend.log` log file
3. Confirm port 8080 is not in use
4. Manually install dependencies: Enter frontend directory and run `npm install`
### Process Won't Stop
1. Manually find process: `tasklist | findstr python`
2. Force stop: `taskkill /F /IM python.exe`
3. Check port: `netstat -ano | findstr :3000`
## Advanced Usage
### Modify Ports
- Backend: Modify port number in `api_server.py`
- Frontend: Modify port number in `vite.config.js`
- After modification, need to sync update port checking logic in scripts
### Custom Log Location
- Modify `LOG_FILE` variable in scripts
- Ensure directory exists and has write permissions
## Technical Support
If you encounter issues, please check:
1. Log files (backend.log, frontend.log)
2. PID files (backend.pid, frontend.pid)
3. Port usage (netstat -ano)
4. Process list (tasklist)

9
script/start.bat Normal file
View File

@@ -0,0 +1,9 @@
@echo off
chcp 65001 >nul
setlocal
cd /d %~dp0
REM Launch via PowerShell to avoid encoding issues with Chinese characters
powershell -ExecutionPolicy Bypass -File start.ps1
timeout /t 3

109
script/start.ps1 Normal file
View File

@@ -0,0 +1,109 @@
# ProxyPool Startup Script
$rootPath = Split-Path $PSScriptRoot -Parent
Write-Host "=== ProxyPool Startup ===" -ForegroundColor Cyan
Write-Host ""
# 1. Clean processes on ports 8923 and 6173
Write-Host "[1/4] Cleaning old processes..." -ForegroundColor Cyan
$ports = @(8923, 6173)
foreach ($port in $ports) {
try {
$conn = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if ($conn) {
$processId = $conn.OwningProcess
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
Write-Host " Stopped port $port (PID: $processId)" -ForegroundColor Gray
}
} catch {}
}
Write-Host " Cleanup complete!" -ForegroundColor Green
Write-Host ""
# 2. Start Backend (FastAPI)
Write-Host "[2/4] Starting backend (FastAPI)..." -ForegroundColor Cyan
$venvPython = "$rootPath\venv\Scripts\python.exe"
if (Test-Path $venvPython) {
$pythonPath = $venvPython
Write-Host " Using venv: $venvPython" -ForegroundColor Green
} else {
$pythonPath = (Get-Command python).Source
Write-Host " Using system Python: $pythonPath" -ForegroundColor Yellow
}
$env:PYTHONIOENCODING = "utf-8"
$backendLog = "$rootPath\logs\backend_startup.log"
$backendErr = "$rootPath\logs\backend_error.log"
# Clear old logs
if (Test-Path $backendLog) { Remove-Item $backendLog -Force }
if (Test-Path $backendErr) { Remove-Item $backendErr -Force }
# Start backend with -u flag for unbuffered output and redirect logs
$backendProcess = Start-Process -FilePath $pythonPath -ArgumentList "-u", "api_server.py" -WorkingDirectory "$rootPath" -RedirectStandardOutput $backendLog -RedirectStandardError $backendErr -WindowStyle Hidden -PassThru
Write-Host " Backend started (PID: $($backendProcess.Id))" -ForegroundColor Green
Write-Host ""
# 3. Wait for backend to be ready (max 10 seconds)
Write-Host "[3/4] Waiting for backend..." -ForegroundColor Cyan
$maxRetries = 5
$retryCount = 0
$backendReady = $false
while (-not $backendReady -and $retryCount -lt $maxRetries) {
Start-Sleep -Seconds 2
$retryCount++
try {
$response = Invoke-RestMethod -Uri "http://127.0.0.1:8923/" -Method Get -TimeoutSec 2 -ErrorAction Stop
if ($response) {
$backendReady = $true
Write-Host " Backend is ready!" -ForegroundColor Green
}
} catch {
$errMessage = $_.Exception.Message
Write-Host " Waiting... ($retryCount/$maxRetries)" -ForegroundColor Yellow
if (Test-Path $backendLog) {
$lastLog = Get-Content $backendLog -Tail 1 -ErrorAction SilentlyContinue
if ($lastLog) { Write-Host " Log: $lastLog" -ForegroundColor DarkGray }
}
if ($backendProcess.HasExited) {
Write-Host " Backend process exited!" -ForegroundColor Red
Write-Host " Exit code: $($backendProcess.ExitCode)" -ForegroundColor Red
if (Test-Path $backendErr) {
Write-Host "" -ForegroundColor Red
Write-Host "Error log:" -ForegroundColor Red
Get-Content $backendErr -Tail 20 | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
}
$backendReady = $false
break
}
}
}
if (-not $backendReady) {
Write-Host "" -ForegroundColor Red
Write-Host "Backend failed to start!" -ForegroundColor Red
Write-Host "Check error log: $backendErr" -ForegroundColor Red
pause
exit
}
Write-Host ""
# 4. Start Frontend (Vite)
Write-Host "[4/4] Starting frontend (Vite)..." -ForegroundColor Cyan
Start-Process -FilePath "cmd" -ArgumentList "/c npm run dev" -WorkingDirectory "$rootPath\frontend" -WindowStyle Hidden
Write-Host " Frontend started" -ForegroundColor Green
Write-Host ""
Write-Host "=== All services started ===" -ForegroundColor Cyan
Write-Host "Backend: http://127.0.0.1:8923" -ForegroundColor Green
Write-Host "Frontend: http://localhost:6173" -ForegroundColor Green
Write-Host ""
Write-Host "Please open frontend in browser" -ForegroundColor Magenta

9
script/stop.bat Normal file
View File

@@ -0,0 +1,9 @@
@echo off
chcp 65001 >nul
setlocal
cd /d %~dp0
REM Stop processes using PowerShell
powershell -ExecutionPolicy Bypass -Command "& { Write-Host 'Stopping processes on 8923 and 6173...' -ForegroundColor Cyan; $ports = @(8923, 6173); foreach ($port in $ports) { $p = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue; if ($p) { Stop-Process -Id $p.OwningProcess -Force; Write-Host \"Stopped port $port\" } }; Write-Host 'Done.' -ForegroundColor Green }"
timeout /t 2