handle sighup and sigterm properly