Basic shutdown hook behavior using a stack for reverse-ordered shutdown