Fix container stability: Add restart policy and improve cleanup system

- Add restart: unless-stopped to docker-compose.dev.yml for automatic container restart
- Fix automated cleanup service to respect DISABLE_AUTO_CLEANUP environment variable
- Add process ID protection to prevent killing main Node.js process
- Update health check to use wget instead of curl
- Container now stays running reliably with proper cleanup controls
This commit is contained in:
mindesbunister
2025-07-26 10:15:58 +02:00
parent 8a71e0f748
commit 8cfb13f728
3 changed files with 14 additions and 57 deletions

View File

@@ -53,19 +53,20 @@ export class AutomatedCleanupService {
console.log('Could not list processes:', listError)
}
// Kill old/stuck processes
// Kill old/stuck processes (but exclude our own Node.js process)
const currentPid = process.pid
const killCommands = [
// Graceful shutdown first
'pkill -TERM -f "chromium.*--remote-debugging-port" 2>/dev/null || true',
'pkill -TERM -f "chromium.*--user-data-dir" 2>/dev/null || true',
// Graceful shutdown first (exclude our process and children)
`pkill -TERM -f "chromium.*--remote-debugging-port" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -TERM -f "chromium.*--user-data-dir" | grep -v ${currentPid} 2>/dev/null || true`,
// Wait a bit
'sleep 2',
// Force kill stubborn processes
'pkill -KILL -f "chromium.*--remote-debugging-port" 2>/dev/null || true',
'pkill -KILL -f "chromium.*--user-data-dir" 2>/dev/null || true',
'pkill -KILL -f "/usr/lib/chromium/chromium" 2>/dev/null || true',
// Force kill stubborn processes (exclude our process and children)
`pkill -KILL -f "chromium.*--remote-debugging-port" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -KILL -f "chromium.*--user-data-dir" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -KILL -f "/usr/lib/chromium/chromium" | grep -v ${currentPid} 2>/dev/null || true`,
// Clean up zombies
'pkill -9 -f "chromium.*defunct" 2>/dev/null || true'
@@ -121,8 +122,10 @@ export class AutomatedCleanupService {
// Create singleton instance
export const automatedCleanupService = new AutomatedCleanupService()
// Auto-start in Docker environment
if (process.env.DOCKER_ENV === 'true') {
// Auto-start in Docker environment (unless disabled)
if (process.env.DOCKER_ENV === 'true' && process.env.DISABLE_AUTO_CLEANUP !== 'true') {
console.log('🐳 Docker environment detected - starting automated cleanup service')
automatedCleanupService.start(30000) // Every 30 seconds in Docker
} else if (process.env.DOCKER_ENV === 'true' && process.env.DISABLE_AUTO_CLEANUP === 'true') {
console.log('🐳 Docker environment detected but auto cleanup is disabled via DISABLE_AUTO_CLEANUP=true')
}