cli: Register signal handlers for SIGTERM/SIGINT
When run under a systemd service, the default stop command is to kill the process; By default, Python doesn't trap sigterm and terminates the process immediately, so even finally blocks don't run.
This traps SIGTERM and SIGINT (^C) signals and raises an exception, allowing the process to exit in an orderly fashion.
Test Plan
It's not obvious how to actually test this. click.testing's CliRunner doesn't support running commands in a separate thread, and running stuff in a separate process is brittle as well.
Migrated from D2283 (view on Phabricator)