catch SIGTERM and SIGINT to exit cleanly