配置
创建uwsgi.ini配置文件,配置内容如下:
[uwsgi]
# Django-related settings
# python manage.py runserver
http = 172.17.0.2:42014
;nginx时使用
;socket = 192.168.88.61:8000
# 项目路径
chdir = /home/your_project
home=/home/your_project/your_module
wsgi-file = /home/your_project/your_module/wsgi.py
# 主进程
master = true
# 指定工作进程
processes = 4
# 每个工作进程2个线程
threads = 1
# 允许在请求中开启新线程
enable-threads=true
# 指后台启动 日志输出的地方
logto = /home/your_project/logs/uwsgi.log
log-maxsize = 102400
# 保存主进程进程号
pidfile = /home/your_project/logs/pid_uwsgi.pid
# 虚拟环境路径
virtualenv = /home/venv
static-map = /static=/home/your_project/static
#不记录request日志,只记录错误日志
disable-logging = true
# 设置工作进程使用虚拟内存超过N MB就回收重启
reload-on-as = 1024
# 设置工作进程使用物理内存超过N MB就回收重启
reload-on-rss = 1024
;evil-reload-on-as = 512
;evil-reload-on-rss = 512
# 设置工作进程每处理N个进程就会被回收重启
max-requests = 1000
# worker进程工作时长
max-worker-lifetime = 3600
# 设置平滑的重启(直到处理完接收到的请求)的长等待时间(秒)
worker-reload-mercy = 60
# 配置django的环境配置文件
env = DJANGO_SETTINGS_MODULE=your_module.settings_dev
启动
uwsgi --ini uwsgi.ini &
查看进程
ps -ef | grep uwsgi
部署脚本
vim deploy.sh
#!/bin/bash
cd /home/your_project/
uwsgi_pid_exist=`ps ax|grep uwsgi.ini |grep -v "grep uwsgi.ini"|xargs -l | awk '{print $1}' | awk 'NR==1{print}'`
uwsgi_pid=`head -1 /home/your_project/logs/pid_uwsgi.pid`
sleep 1
echo "git update code..."
git pull origin master
echo "git update done..."
sleep 3
if test -n "$uwsgi_pid"
then
echo "process $uwsgi_pid restart now..."
if test -n "$uwsgi_pid_exist"
then
uwsgi --reload /home/your_project/logs/pid_uwsgi.pid &
else
uwsgi --ini uwsgi.ini &
fi
else
echo "start fisrt time"
uwsgi --ini uwsgi.ini &
fi
其中pid文件为uwsgi.ini中指定的配置文件位置
pidfile = /home/your_project/logs/pid_uwsgi.pid