Repository: jupyterhub/jupyterhub

Issue:
sqlAlch Operational error
Had to hard reboot my computer. 

Db seem readonly (lock file ? ) 

Should probably be catched, and exit with error code. 

```
[E 2015-03-06 16:13:05.801 JupyterHub ioloop:588] Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x10d9b27b8>, <tornado.concurrent.Future object at 0x10d951710>)
    Traceback (most recent call last):
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/ioloop.py", line 568, in _run_callback
        ret = callback()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/stack_context.py", line 275, in null_wrapper
        return fn(*args, **kwargs)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/ioloop.py", line 574, in <lambda>
        self.add_future(ret, lambda f: f.result())
      File "/Users/bussonniermatthias/dev/jupyterhub/jupyterhub/app.py", line 999, in launch_instance_async
        yield self.initialize(argv)
      File "/Users/bussonniermatthias/dev/jupyterhub/jupyterhub/app.py", line 845, in initialize
        yield self.init_users()
      File "/Users/bussonniermatthias/dev/jupyterhub/jupyterhub/app.py", line 672, in init_users
        db.commit()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 776, in commit
        self.transaction.commit()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 377, in commit
        self._prepare_impl()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 357, in _prepare_impl
        self.session.flush()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 1919, in flush
        self._flush(objects)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush
        transaction.rollback(_capture_exception=True)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
        compat.reraise(exc_type, exc_value, exc_tb)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 182, in reraise
        raise value
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2001, in _flush
        flush_context.execute()
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 372, in execute
        rec.execute(self)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 526, in execute
        uow
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 60, in save_obj
        mapper, table, update)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 518, in _emit_update_statements
        execute(statement, params)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 729, in execute
        return meth(self, multiparams, params)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
        return connection._execute_clauseelement(self, multiparams, params)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
        compiled_sql, distilled_params
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
        context)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1159, in _handle_dbapi_exception
        exc_info
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 188, in raise_from_cause
        reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 181, in reraise
        raise value.with_traceback(tb)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
        context)
      File "/usr/local/Cellar/python3/HEAD/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
        cursor.execute(statement, parameters)
    sqlalchemy.exc.OperationalError: (OperationalError) attempt to write a readonly database 'UPDATE users SET _server_id=? WHERE users.id = ?' (None, 2)
```



Discussion:
Actually the DB was own by root also.


Resolving patch:
diff --git a/jupyterhub/app.py b/jupyterhub/app.py
--- a/jupyterhub/app.py
+++ b/jupyterhub/app.py
@@ -1011,8 +1011,12 @@ def stop(self):
     
     @gen.coroutine
     def launch_instance_async(self, argv=None):
-        yield self.initialize(argv)
-        yield self.start()
+        try:
+            yield self.initialize(argv)
+            yield self.start()
+        except Exception as e:
+            self.log.exception("")
+            self.exit(1)
     
     @classmethod
     def launch_instance(cls, argv=None):


Test patch: