From 05d32ae70537b590b08cf0c533a1ee20e8032563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Sat, 14 Dec 2019 18:16:31 +0100 Subject: [PATCH] Massive speedup in executing startup_scripts --- docker/docker-entrypoint.sh | 5 +---- startup_scripts/__main__.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 startup_scripts/__main__.py diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 2e6a8de..0c8d2a1 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -45,10 +45,7 @@ fi 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 + echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python fi # copy static files diff --git a/startup_scripts/__main__.py b/startup_scripts/__main__.py new file mode 100644 index 0000000..50d2613 --- /dev/null +++ b/startup_scripts/__main__.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import runpy +from os import scandir +from os.path import dirname, abspath + +this_dir = dirname(abspath(__file__)) + +def filename(f): + return f.name + +with scandir(dirname(abspath(__file__))) as it: + for f in sorted(it, key = filename): + if f.name.startswith('__') or not f.is_file(): + continue + + print(f"Running {f.path}") + runpy.run_path(f.path)