feat: implement robust browser process cleanup system
- Add cleanup-chromium.sh script for manual zombie process cleanup - Add docker-entrypoint.sh with signal handlers for graceful shutdown - Add lib/process-cleanup.ts for automatic cleanup on app termination - Enhanced forceCleanup() method in tradingview-automation.ts: - Individual page closing before browser termination - Force kill remaining processes with SIGKILL - Reset operation locks after cleanup - Improved browser launch args to prevent zombie processes: - Better crash reporter handling - Enhanced background process management - Removed problematic --single-process flag - Updated Dockerfile to use new entrypoint with cleanup handlers - Set DOCKER_ENV environment variable for container detection - Add proper signal handling (SIGINT, SIGTERM, SIGQUIT) - Automatic cleanup of temporary Puppeteer profiles Resolves zombie Chromium process accumulation issue
This commit is contained in:
34
docker-entrypoint.sh
Executable file
34
docker-entrypoint.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Trading Bot Startup Script with Process Cleanup
|
||||
# This script initializes the process cleanup handlers and starts the Next.js app
|
||||
|
||||
echo "🚀 Starting Trading Bot with Process Cleanup..."
|
||||
|
||||
# Initialize process cleanup
|
||||
echo "🧹 Initializing process cleanup handlers..."
|
||||
|
||||
# Create a signal handler to cleanup on container stop
|
||||
cleanup() {
|
||||
echo "🛑 Received shutdown signal, cleaning up..."
|
||||
|
||||
# Kill any remaining chromium processes
|
||||
pkill -f "chromium" 2>/dev/null || true
|
||||
|
||||
# Clean up temporary files
|
||||
rm -rf /tmp/puppeteer_dev_chrome_profile-* 2>/dev/null || true
|
||||
|
||||
echo "✅ Cleanup completed"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Register signal handlers
|
||||
trap cleanup SIGINT SIGTERM SIGQUIT
|
||||
|
||||
# Start the Next.js application
|
||||
echo "🚀 Starting Next.js application..."
|
||||
if [ "$NODE_ENV" = "development" ]; then
|
||||
exec npm run dev:docker
|
||||
else
|
||||
exec npm start
|
||||
fi
|
||||
Reference in New Issue
Block a user