Add better shutdown checking in SIGTERM