Added Daemon.terminate_callback and changed Daemon._handle_terminate
to first call the terminate_callback and give the process a chance
to close normally. Call _shutdown only when the terminate_callback is not
set or when we have already called it once (meaning it's the second time a
terminating signal arrives)