Merge pull request #128 from ScanPlusGmbH/optimze-startup

Make startup scripts optional
This commit is contained in:
Christian Mäder 2019-03-19 17:12:15 +01:00 committed by GitHub
commit e17baea76c
No account linked to committer's email address
2 changed files with 9 additions and 4 deletions

View File

@ -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) ### 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`. 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: That mechanism can be used for many things, e.g. to create Netbox custom fields:

View File

@ -39,10 +39,14 @@ if not User.objects.filter(username='${SUPERUSER_NAME}'):
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}') Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}')
END END
for script in /opt/netbox/startup_scripts/*.py; do if [ "$SKIP_STARTUP_SCRIPTS" == "true" ]; then
echo "⚙️ Executing '$script'" echo "☇ Skipping startup scripts"
./manage.py shell --interface python < "${script}" else
done for script in /opt/netbox/startup_scripts/*.py; do
echo "⚙️ Executing '$script'"
./manage.py shell --interface python < "${script}"
done
fi
# copy static files # copy static files
./manage.py collectstatic --no-input ./manage.py collectstatic --no-input