# django-server-controller
Django server controllers, e.g. UwsgiController, GunicornController.
## Install
```shell
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_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.
1. settings.WSGI_PROJECT_BASE + "./etc/wsgi.ini"
1. ./etc/wsgi.ini
1. ~/etc/wsgi.ini
1. 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.
1. settings.WSGI_PROJECT_BASE + "./etc/wsgi.conf.py"
1. ./etc/wsgi.conf.py
1. ~/etc/wsgi.conf.py
1. 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
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
chdir = /home/your-project-name
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.1.0
- First release.
### v0.1.1
- Fix psutil import problem.
### v0.1.2
- Fix reload parameter problem.
### v0.1.3
- Fix time import problem.
### v0.2.0
- Use as django's command.
### v0.2.1
- Add django-click in requriements.txt.
- Change uwsgi_ini_file search order, and uwsgi_bin search order.
- Update document.
### v0.3.0
- Add GunicornController.
### v0.3.2
- Add project_base folder to uwsgi/gunicorn's pythonpath.
### 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.5.0
- Set default web root to project base.
### v0.5.1
- Doc update.
Raw data
{
"_id": null,
"home_page": "",
"name": "django-server-controller",
"maintainer": "Li ZhengBo",
"docs_url": null,
"requires_python": "",
"maintainer_email": "lizhengbo@zencore.cn",
"keywords": "django-server-controller,UwsgiController,GunicornController",
"author": "Li ZhengBo",
"author_email": "lizhengbo@zencore.cn",
"download_url": "https://files.pythonhosted.org/packages/51/5e/aa48c8cc12af7a12dcf11dcea3a0593f284ae13af08024a7e4e369c7711c/django-server-controller-0.5.1.tar.gz",
"platform": null,
"description": "# django-server-controller\n\nDjango server controllers, e.g. UwsgiController, GunicornController.\n\n## Install\n\n```shell\npip install django-server-controller\n```\n\n## Django Command Help\n\n```\nC:\\Workspace\\my_django_project>python manage.py wsgi-server --help\nUsage: manage.py wsgi-server [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n --version Show the version and exit.\n -h, --help Show this message and exit.\n -v, --verbosity INTEGER RANGE Verbosity level; 0=minimal output, 1=normal\n output, 2=verbose output, 3=very verbose\n output.\n\n --settings SETTINGS The Python path to a settings module, e.g.\n \"myproject.settings.main\". If this is not\n provided, the DJANGO_SETTINGS_MODULE\n environment variable will be used.\n\n --pythonpath PYTHONPATH A directory to add to the Python path, e.g.\n \"/home/djangoprojects/myproject\".\n\n --traceback / --no-traceback Raise on CommandError exceptions.\n --color / --no-color Enable or disable output colorization.\n Default is to autodetect the best behavior.\n\n\nCommands:\n reload Reload uwsgi server.\n restart Restart uwsgi server.\n start Start uwsgi server.\n status Get uwsgi server's status.\n stop Stop uwsgi server.\n```\n\n## Usage\n\n**pro/settings.py**\n\n```\nINSTALLED_APPS = [\n ...\n 'django_server_controller',\n ...\n]\n\nWSGI_SERVER_ENGINE = \"uwsgi\" # required. uwsgi or gunicorn, default to uwsgi.\n\n#\n# optional config items\n#\nWSGI_PROJECT_NAME = xxx # used for name of the default pidfile\nWSGI_PROJECT_BASE = xxx\nWSGI_LOGS_ROOT = xxx\nWSGI_PIDFILE = xxx\nWSGI_CONFIG_FILE = xxx\nWSGI_BIN = xxx\nKILL_BIN = xxx # used for send signal to gunicorn process, no use for uwsgi\n\n```\n\n- Add django_server_controller into INSTALLED_APPS, so that we can use it's django-management-commands.\n- You can add server settings in django's settings.py. If not provide, the default values are used.\n- UWSGI_PROJECT_BASE defaults to current directory. *Suggest you set this variable*.\n- CONFIG_FILE search orders for uwsgi server engine:\n 1. settings.CONFIG_FILE pointed file.\n 1. settings.WSGI_PROJECT_BASE + \"./etc/wsgi.ini\"\n 1. ./etc/wsgi.ini\n 1. ~/etc/wsgi.ini\n 1. python-lib-root/lib/python3.6/site-packages/the_project_package/wsgi.ini\n- CONFIG_FILE search orders for gunicorn server engine:\n 1. settings.CONFIG_FILE pointed file.\n 1. settings.WSGI_PROJECT_BASE + \"./etc/wsgi.conf.py\"\n 1. ./etc/wsgi.conf.py\n 1. ~/etc/wsgi.conf.py\n 1. python-lib-root/lib/python3.6/site-packages/the_project_package/wsgi.conf.py\n\n\n## Suggest project folders\n\n```\n./bin/\n./etc/\n./lib/\n./lib64/\n./web/\n./web/static/\n./web/upload/\n./logs/\n```\n\n- suggest you use virtualenv.\n- bin/lib/lib64 folders are created by virutalenv.\n- etc/web/logs folders are ours.\n\n## Example template of wsgi.ini\n\n```\n[uwsgi]\nsocket=0.0.0.0:5501\nhttp=0.0.0.0:5502\nstats=0.0.0.0:5503\nchdir=/home/your-project-name\nprocesses=2\nthreads=40\nlisten=1024\nmaster=True\ndaemonize=/home/your-project-name/logs/uwsgi.log\n```\n\n## Example template of wsgi.conf.py\n\n```\nbind = [\"0.0.0.0:5505\"]\nworkers = 2\nthreads = 40\nmax_requests = 10000\ndaemon = True\nchdir = /home/your-project-name\naccesslog = \"/var/logs/pro1/gunicorn.access.log\"\nerrorlog = \"/var/logs/pro1/gunicorn.error.log\"\nkeepalive = 300\ntimeout = 300\ngraceful_timeout = 300\nloglevel = \"info\"\n```\n\n*Notice*\n\n- 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.\n\n## Releases\n\n### v0.1.0\n\n- First release.\n\n### v0.1.1\n\n- Fix psutil import problem.\n\n### v0.1.2\n\n- Fix reload parameter problem.\n\n### v0.1.3\n\n- Fix time import problem.\n\n### v0.2.0\n\n- Use as django's command.\n\n### v0.2.1\n\n- Add django-click in requriements.txt.\n- Change uwsgi_ini_file search order, and uwsgi_bin search order.\n- Update document.\n\n### v0.3.0\n\n- Add GunicornController.\n\n### v0.3.2\n\n- Add project_base folder to uwsgi/gunicorn's pythonpath.\n\n### v0.4.0\n\n- Stop command will wait for server to stop. Use --force to kill the server by force if stopping timeout.\n- Add subcommand show-wsgi-config-file to show current wsgi.conf.py path.\n- Add subcommand show-wsgi-config-file-paths to show wsgi.conf.py searching paths.\n\n### v0.5.0\n\n- Set default web root to project base.\n\n### v0.5.1\n\n- Doc update.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django server controllers, e.g. UwsgiController, GunicornController.",
"version": "0.5.1",
"project_urls": null,
"split_keywords": [
"django-server-controller",
"uwsgicontroller",
"gunicorncontroller"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c0b23a37c21cf929fd9de7476b93149c4d06f34f498fd64b986683bb704de2ac",
"md5": "da46bcfad0f5147c2ab8b8d3ee61498e",
"sha256": "02ecb054e5ba2cd624b5315b3c286bda1941ed6d108575e7a342c457d784fc5a"
},
"downloads": -1,
"filename": "django_server_controller-0.5.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "da46bcfad0f5147c2ab8b8d3ee61498e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8535,
"upload_time": "2023-09-14T12:38:21",
"upload_time_iso_8601": "2023-09-14T12:38:21.047781Z",
"url": "https://files.pythonhosted.org/packages/c0/b2/3a37c21cf929fd9de7476b93149c4d06f34f498fd64b986683bb704de2ac/django_server_controller-0.5.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "515eaa48c8cc12af7a12dcf11dcea3a0593f284ae13af08024a7e4e369c7711c",
"md5": "2ea7d9cef15a9ce62e7f2f3faa5ae526",
"sha256": "35e270a1da4526dc5e8459b4a68a2b7db69f5b417f03542a1c68336fe29c3c60"
},
"downloads": -1,
"filename": "django-server-controller-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "2ea7d9cef15a9ce62e7f2f3faa5ae526",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9207,
"upload_time": "2023-09-14T12:38:22",
"upload_time_iso_8601": "2023-09-14T12:38:22.189271Z",
"url": "https://files.pythonhosted.org/packages/51/5e/aa48c8cc12af7a12dcf11dcea3a0593f284ae13af08024a7e4e369c7711c/django-server-controller-0.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-14 12:38:22",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-server-controller"
}