Supporting graceful signal shutdown.

Adding a signal handler and gracefully shutting down all threads.