Gracefully handle Ctrl+C and SIGTERM