This hook approach allows program to keep running but being able to handle exiting of the program in the dynamic way. Fixes #2377
* Add a generic registerShutdown function for graceful exit * Add shutdown callback test case