Install a signal handler to catch Ctrl-C and SIGTERM and shutdown cleanly