Don't attempt to login if device key is missing
Split webserver.run into prepare+start and add stop function
Used by mod-app, syncs to py3 code