Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to start wsgi server for Django
#!/bin/sh
# NOTE: this script will be executed inside a docker container
# parameter
# start_wsgi_server.sh dev sms_api_gateway.settings.cloud_dev
if [ $# -ne 2 ]; then
echo $0: usage: start_wsgi_server.sh DJANGO_ENV DJANGO_SETTINGS
exit 1
fi
DJANGO_ENV=$1
DJANGO_SETTINGS=$2
# main
echo "DJANGO_ENV:${DJANGO_ENV}"
echo "DJANGO_SETTINGS:${DJANGO_SETTINGS}"
cd /app/src/ # NOTE: this script will be executed inside a docker container
word='cloud_dev'
# word='local_dev'
string=${DJANGO_SETTINGS}
# test "${string#*$word}" != "$string" && <command>
# prepare database and static files
# this line has moved to ci/cd pipeline:
# This script has to be executed in docker container!
test "${string#*$word}" != "$string" && ../start_prepare_database.sh ${DJANGO_ENV} ${DJANGO_SETTINGS}
test "${string#*$word}" != "$string" && python manage.py shell --settings ${DJANGO_SETTINGS} < ../createadmin.py
# START UWSGI
# This command starts the uwsgi-server
echo "RUN: uwsgi..."
uwsgi --chdir /app \
--wsgi-file /app/src/sms_api_gateway/wsgi/${DJANGO_ENV}.py \
--master \
--workers 1 \
--max-requests 10000 \
--harakiri 60 \
--static-map /static=/app/src/staticfiles \
--static-map /media=/app/src/media \
--http-auto-gzip \
--static-gzip-all \
--vacuum \
--http :5000 \
--https 0.0.0.0:8443,/app/infrastructure/ssl/sms-api-gateway.com.crt.pem,/app/infrastructure/ssl/sms-api-gateway.com.key.pem \
--socket :5001
# --socket :5001 # wsgi port / web service gateway interface
# --https 0.0.0.0:8443,foobar.crt,foobar.key
# --enable-threads \
# --single-interpreter \
# --stats :1717 \
# socket = /run/uwsgi/cioenglish.sock
# post-buffering
# auto-procname
# procname-prefix-spaced
# Serving static files with uWSGI (updated to 1.9)
# ------------------------------------------------------------------------------
# See: https://uwsgi-docs.readthedocs.io/en/latest/StaticFiles.html
# Example:
# uwsgi --chdir=/path/to/your/project \
# --module=mysite.wsgi:application \
# --env DJANGO_SETTINGS_MODULE=mysite.settings \
# --master --pidfile=/tmp/project-master.pid \
# --socket=127.0.0.1:49152 \ # can also be a file
# --processes=5 \ # number of worker processes
# --uid=1000 --gid=2000 \ # if root, uwsgi can drop privileges
# --harakiri=20 \ # respawn processes taking more than 20 seconds
# --max-requests=5000 \ # respawn processes after serving 5000 requests
# --vacuum \ # clear environment on exit
# --home=/path/to/virtual/env \ # optional path to a virtualenv
# --daemonize=/var/log/uwsgi/yourproject.log # background the process
#
# --static-cache-paths
# --static-cache-paths 30 \ # will cache each static file translation for 30 seconds in the uWSGI cache.
# --static-safe
# --static-safe /tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment