uwsgi部署flask应用
2017/10/3大约 2 分钟约 487 字
uwsgi配置
配置文件config.ini
[uwsgi]
socket = 127.0.0.1:8001
# python module
module = blog:app
processes = 1 //处理器个数
threads = 2 //线程个数
master = true
home = venv //python 的位置,这里是virtualenv
pidfile=/var/run/uwsgi.pid // pidfile 便于停止进程nginx配置
location /admin {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
uwsgi_param UWSGI_PYHOME /www/blog/venv;
uwsgi_param UWSGI_CHDIR /www/blog;
uwsgi_param UWSGI_SCRIPT blog:app; # 指定启动程序
}配置其实不难,按这个做应该就不会有大问题,一些小坑还得看文档或Google
OK, 现在手动启动uwsgi, 服务应该可以启动了。
编写脚本
参考了以下资料 uwsgi加入系统服务LSB_WikiLinux应用程序编程界面规范.pdf
然后弄了个基本能用的脚本
➜ ~ service uwsgi start
➜ ~ service uwsgi status
● uwsgi.service - LSB: uwsgi
Loaded: loaded (/etc/init.d/uwsgi; generated; vendor preset: enabled)
Active: active (exited) since Wed 2017-10-04 03:46:01 EDT; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 1826 ExecStart=/etc/init.d/uwsgi start (code=exited, status=0/SUCCESS)
Oct 04 03:46:01 XXXX systemd[1]: Starting LSB: uwsgi...
Oct 04 03:46:01 XXXX systemd[1]: Started LSB: uwsgi.#!/bin/bash
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 2 6
# Description: uwsgi
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi
DAEMON=uwsgi
SCRIPTNAME=/etc/init.d/$NAME
CONFFILE=/etc/uwsgi/uwsgi.ini
PIDFILE=/var/run/uwsgi.pid
test -x $DAEMON || exit 0
d_start(){
$DAEMON $CONFFILE || echo -n " already running"
}
d_stop() {
$DAEMON --stop $PIDFILE || echo -n " not running"
}
d_reload() {
$DAEMON --reload $PIDFILE || echo -n " counld not reload"
}
d_freload() {
$DAEMON --die-on-term $PIDFILE || echo -n " counld not force reload"
}
case "$1" in
start)
echo -n "Starting $DESC:$NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC:$NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
force_reload)
echo -n "The official provision of the parameters, tested and found not to support..."
# d_freload
# echo "force reloaded."
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 2
d_start
echo "."
;;
status)
echo -n "Status:"
cat $PIDFILE
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force_reload}" >&2
exit 3
;;
esac
exit 0