Feature/graceful shutdown

Retarget of #593. Not currently functioning due to missing `StopServer()` method.