Skip to main content

Django server controllers, e.g. UwsgiController, GunicornController.

Project description

django-server-controller

Django server controllers, e.g. UwsgiController, GunicornController.

Install

pip install django-server-controller

Django Command Help

C:\Workspace\my_django_project>python manage.py wsgi-server --help
Usage: manage.py wsgi-server [OPTIONS] COMMAND [ARGS]...

Options:
  --version                      Show the version and exit.
  -h, --help                     Show this message and exit.
  -v, --verbosity INTEGER RANGE  Verbosity level; 0=minimal output, 1=normal
                                 output, 2=verbose output, 3=very verbose
                                 output.

  --settings SETTINGS            The Python path to a settings module, e.g.
                                 "myproject.settings.main". If this is not
                                 provided, the DJANGO_SETTINGS_MODULE
                                 environment variable will be used.

  --pythonpath PYTHONPATH        A directory to add to the Python path, e.g.
                                 "/home/djangoprojects/myproject".

  --traceback / --no-traceback   Raise on CommandError exceptions.
  --color / --no-color           Enable or disable output colorization.
                                 Default is to autodetect the best behavior.


Commands:
  reload   Reload uwsgi server.
  restart  Restart uwsgi server.
  start    Start uwsgi server.
  status   Get uwsgi server's status.
  stop     Stop uwsgi server.

Usage

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_server_controller',
    ...
]

WSGI_SERVER_ENGINE = "uwsgi"   # required. uwsgi or gunicorn, default to uwsgi.

#
# optional config items
#
WSGI_PROJECT_NAME = xxx # used for name of the default pidfile
WSGI_PROJECT_BASE = xxx
WSGI_WEB_ROOT = xxx # chdir to web root before starting server
WSGI_LOGS_ROOT = xxx
WSGI_PIDFILE = xxx
WSGI_CONFIG_FILE = xxx
WSGI_BIN = xxx
KILL_BIN = xxx # used for send signal to gunicorn process, no use for uwsgi

  • Add django_server_controller into INSTALLED_APPS, so that we can use it's django-management-commands.
  • You can add server settings in django's settings.py. If not provide, the default values are used.
  • UWSGI_PROJECT_BASE defaults to current directory. Suggest you set this variable.
  • CONFIG_FILE search orders for uwsgi server engine:
    1. settings.CONFIG_FILE pointed file.
    2. settings.WSGI_PROJECT_BASE + "./etc/wsgi.ini"
    3. ./etc/wsgi.ini
    4. ~/etc/wsgi.ini
    5. python-lib-root/lib/python3.6/site-packages/the_project_package/wsgi.ini
  • CONFIG_FILE search orders for gunicorn server engine:
    1. settings.CONFIG_FILE pointed file.
    2. settings.WSGI_PROJECT_BASE + "./etc/wsgi.conf.py"
    3. ./etc/wsgi.conf.py
    4. ~/etc/wsgi.conf.py
    5. python-lib-root/lib/python3.6/site-packages/the_project_package/wsgi.conf.py

Suggest project folders

./bin/
./etc/
./lib/
./lib64/
./web/
./web/static/
./web/upload/
./logs/
  • suggest you use virtualenv.
  • bin/lib/lib64 folders are created by virutalenv.
  • etc/web/logs folders are ours.

Example template of wsgi.ini

[uwsgi]
socket=0.0.0.0:5501
http=0.0.0.0:5502
stats=0.0.0.0:5503
chdir=/home/your-project-name/web
processes=2
threads=40
listen=1024
master=True
daemonize=/home/your-project-name/logs/uwsgi.log

Example template of wsgi.conf.py

bind = ["0.0.0.0:5505"]
workers = 2
threads = 40
max_requests = 10000
daemon = True
accesslog = "/var/logs/pro1/gunicorn.access.log"
errorlog = "/var/logs/pro1/gunicorn.error.log"
keepalive = 300
timeout = 300
graceful_timeout = 300
loglevel = "info"

Notice

  • Many nginx set keepalive to 60 seconds, but gunicorn keepalive defaults to 2 seconds, this may cause many 502 errors. So that set the gunicorn's keepalive value to higher than 60 seoncds, for example 300 seonds.

Releases

v0.4.0

  • Stop command will wait for server to stop. Use --force to kill the server by force if stopping timeout.
  • Add subcommand show-wsgi-config-file to show current wsgi.conf.py path.
  • Add subcommand show-wsgi-config-file-paths to show wsgi.conf.py searching paths.

v0.3.2

  • Add project_base folder to uwsgi/gunicorn's pythonpath.

v0.3.0

  • Add GunicornController.

v0.2.1

  • Add django-click in requriements.txt.
  • Change uwsgi_ini_file search order, and uwsgi_bin search order.
  • Update document.

v0.2.0

  • Use as django's command.

v0.1.3

  • Fix time import problem.

v0.1.2

  • Fix reload parameter problem.

v0.1.1

  • Fix psutil import problem.

v0.1.0

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-server-controller-0.4.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

django_server_controller-0.4.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file django-server-controller-0.4.0.tar.gz.

File metadata

  • Download URL: django-server-controller-0.4.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django-server-controller-0.4.0.tar.gz
Algorithm Hash digest
SHA256 078f1fae6dd41905fe3e086d7175d7194749549d91b245b25560659593d75720
MD5 b9d9e6ff520882e3d3f2b53199ec4bcd
BLAKE2b-256 d138ba88dccc8388c3ff6de555adbc581bf545af61dac3bf45f45e539f60ffcf

See more details on using hashes here.

File details

Details for the file django_server_controller-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: django_server_controller-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django_server_controller-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceee8ebe98f2282bb6c4e324b1bf440ee2ff5d36f05c8c614b9b1e9eb0fd24ca
MD5 53e7801f8dc754315fe9108648246c7a
BLAKE2b-256 605c4a71ddd84db3004a5261deceab152d077c7673ecf6f4e398e461329f396e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page