Cleanup sigint code [#3500]
Closes #3500 (closed). Moves SIGINT handling to a helper function, adds SIGTERM handling.
Changelog: refactor
Closes #3500 (closed). Moves SIGINT handling to a helper function, adds SIGTERM handling.
Changelog: refactor