Support graceful shutdown and restart