Skip to content

Commit

Permalink
Merge pull request #207 from netbox-community/speedup_startup_scripts
Browse files Browse the repository at this point in the history
Massive speedup in executing startup_scripts
  • Loading branch information
cimnine authored Dec 16, 2019
2 parents 8506500 + 05d32ae commit b48de9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 1 addition & 4 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions startup_scripts/__main__.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b48de9f

Please sign in to comment.