Generic shutdown impl