diff --git a/openquake/commands/webui.py b/openquake/commands/webui.py index 990c68698578..b743ccbb3235 100644 --- a/openquake/commands/webui.py +++ b/openquake/commands/webui.py @@ -22,11 +22,12 @@ import webbrowser from openquake.baselib import config, general -from openquake.server import dbserver, db +from openquake.server import dbserver from openquake.server.utils import check_webserver_running commands = ['start'] + def runserver(hostport=None, skip_browser=False): args = [sys.executable, '-m', 'openquake.server.manage', 'runserver'] # the reload functionality of the Django development server interferes @@ -56,8 +57,6 @@ def main(cmd, hostport='127.0.0.1:8800', skip_browser: bool = False): sys.exit('This command must be run by the proper user: ' 'see the documentation for details') dbserver.ensure_on() # start the dbserver in a subprocess - # reset any computation left in the 'executing' state - db.actions.reset_is_running(dbserver.db) print('Starting, using version %s' % general.engine_version()) runserver(hostport, skip_browser) diff --git a/openquake/server/apps.py b/openquake/server/apps.py index 782e276d7c15..4633c34f8596 100644 --- a/openquake/server/apps.py +++ b/openquake/server/apps.py @@ -19,7 +19,9 @@ import os from django.apps import AppConfig from django.conf import settings +from sqlite3 import OperationalError from openquake.baselib import config +from openquake.server import dbserver, db class ServerConfig(AppConfig): @@ -34,6 +36,13 @@ def ready(self): # AppConfig classes are defined, you can import them in ready() import openquake.server.signals # NOQA + # reset any computation left in the 'executing' state + try: + db.actions.reset_is_running(dbserver.db) + except OperationalError: + # in the action "docs" the database does not exist + pass + if settings.APPLICATION_MODE not in settings.APPLICATION_MODES: raise ValueError( f'Invalid application mode: "{settings.APPLICATION_MODE}".'