[Issue #7] Add support for graceful shutdowns.