From 8c95f32b0caf5e83df04fd2071d43da954150fea Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Thu, 28 Feb 2019 09:20:10 +0100 Subject: [PATCH] Make startup scripts optional To optimize the application boot time the startup scripts can now be disabled by an ENV variable. The default when the variable is not set, is to run the startup scripts. This means that the default behaviour is not changed from earlier releases. --- README.md | 1 + docker/docker-entrypoint.sh | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52ca8f9..0424e6f 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ You can also dynamically add any other report to this same directory and Netbox ### Custom Initialization Code (e.g. Automatically Setting Up Custom Fields) When using `docker-compose`, all the python scripts present in `/opt/netbox/startup_scripts` will automatically be executed after the application boots in the context of `./manage.py`. +The execution of the startup scripts can be prevented by setting the environment variable `SKIP_STARTUP_SCRIPTS` to `true`, e.g. in the file `env/netbox.env`. That mechanism can be used for many things, e.g. to create Netbox custom fields: diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 4cef815..8922a5d 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -39,10 +39,14 @@ if not User.objects.filter(username='${SUPERUSER_NAME}'): Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}') END -for script in /opt/netbox/startup_scripts/*.py; do - echo "⚙️ Executing '$script'" - ./manage.py shell --interface python < "${script}" -done +if [ "$SKIP_STARTUP_SCRIPTS" == "true" ]; then + echo "☇ Skipping startup scripts" +else + for script in /opt/netbox/startup_scripts/*.py; do + echo "⚙️ Executing '$script'" + ./manage.py shell --interface python < "${script}" + done +fi # copy static files ./manage.py collectstatic --no-input