Skip to content

Commit 05d32ae

Browse files
committed
Massive speedup in executing startup_scripts
1 parent fd95554 commit 05d32ae

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

docker/docker-entrypoint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ fi
4545
if [ "$SKIP_STARTUP_SCRIPTS" == "true" ]; then
4646
echo "↩️ Skipping startup scripts"
4747
else
48-
for script in /opt/netbox/startup_scripts/*.py; do
49-
echo "⚙️ Executing '$script'"
50-
./manage.py shell --interface python < "${script}"
51-
done
48+
echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python
5249
fi
5350

5451
# copy static files

startup_scripts/__main__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import runpy
4+
from os import scandir
5+
from os.path import dirname, abspath
6+
7+
this_dir = dirname(abspath(__file__))
8+
9+
def filename(f):
10+
return f.name
11+
12+
with scandir(dirname(abspath(__file__))) as it:
13+
for f in sorted(it, key = filename):
14+
if f.name.startswith('__') or not f.is_file():
15+
continue
16+
17+
print(f"Running {f.path}")
18+
runpy.run_path(f.path)

0 commit comments

Comments
 (0)