diff --git a/InvenTree/InvenTree/management/commands/wait_for_db.py b/InvenTree/InvenTree/management/commands/wait_for_db.py new file mode 100644 index 0000000000..5d152d26ca --- /dev/null +++ b/InvenTree/InvenTree/management/commands/wait_for_db.py @@ -0,0 +1,31 @@ +""" +Custom management command, wait for the database to be ready! +""" + +from django.core.management.base import BaseCommand + +from django.db import connections +from django.db.utils import OperationalError + +import time + + +class Command(BaseCommand): + """ + django command to pause execution until the database is ready + """ + + def handle(self, *args, **kwargs): + self.stdout.write("Waiting for database...") + + db_conn = None + + while not db_conn: + try: + # get the database with keyword 'default' from settings.py + db_conn = connections['default'] + # prints success messge in green + self.stdout.write(self.style.SUCCESS('InvenTree database connected')) + except OperationalError: + self.stdout.write("Database unavailable, waiting 5 seconds ...") + time.sleep(5) diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index bab673306f..7ce62e887d 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -9,11 +9,6 @@ database: # Uncomment (and edit) one of the database configurations below, # or specify database options using environment variables - - # Default installation uses a simple sqlite database - # For production, consider changing this! - ENGINE: sqlite3 - NAME: '/home/inventree/database.sqlite3' # Refer to the django documentation for full list of options diff --git a/docker/Dockerfile b/docker/Dockerfile index 4d59ec4b8e..c49c6e53f0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -23,6 +23,7 @@ ENV INVENTREE_PORT="${INVENTREE_PORT}" # InvenTree paths ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src" +ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree" ENV INVENTREE_STATIC_ROOT="${INVENTREE_HOME}/static" ENV INVENTREE_MEDIA_ROOT="${INVENTREE_HOME}/media" ENV INVENTREE_LOG_DIR="${INVENTREE_HOME}/log"