Apply shutdown hook to both copy and query modes