case "$1" in
start)
if [ $uwsgi_pn -ge 5 ];then
action "uwsgi is running!" /bin/false
else
start
ERVAL=0
fi
;;
stop)
if [ $uwsgi_pn -ge 5 ];then
stop
ERVAL=0
else
action "uwsgi no running!" /bin/false
fi
;;
reload)
if [ $uwsgi_pn -ge 5 ];then
$uwsgi --reload $uwsgi_pid >&/dev/null
ERVAL=$?
[ $ERVAL -eq 0 ] && action "uwsgi reloading ..." /bin/true
else
action "uwsgi reload error" /bin/false
fi
;;
restart)
stop
sleep 2
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
ERVAL=2
esac
exit $ERVAL
centOS7 system系统服务脚本:
#cat uwsgi.service
[Unit]
Description=uwsgi service
After=network.target
[Service]
Type=forking
PIDFile=/run/uwsgi.pid
ExecStartPre=/usr/bin/rm -f /run/uwsgi.pid
ExecStart=/usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
测试服务:
#uwsgi --ini /djproject/mysite/uwsgi.ini #启动服务
#ps -ef|grep "uwsgi" #查看进程
root 103596 1 2 16:02 ? 00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
root 103598 103596 0 16:02 ? 00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
root 103599 103596 0 16:02 ? 00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
#netstat -lntp|grep "uwsgi"
tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 103596/uwsgi
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 103596/uwsgi
看上面进程是少了一个主进程,通过systemctl 查看就清楚了:
#systemctl status -l uwsgi.service
● uwsgi.service - uwsgi service
Loaded: loaded (/usr/lib/systemd/system/uwsgi.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2018-05-25 16:02:06 CST; 4min 14s ago
Process: 103593 ExecStart=/usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini (code=exited, status=0/SUCCESS)
Process: 103591 ExecStartPre=/usr/bin/rm -f /run/uwsgi.pid (code=exited, status=0/SUCCESS)
Main PID: 103596 (uwsgi)
CGroup: /system.slice/uwsgi.service
├─103596 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
├─103598 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
└─103599 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
5月 25 16:02:06 ZPY systemd[1]: Starting uwsgi service...
5月 25 16:02:06 ZPY uwsgi[103593]: [uWSGI] getting INI configuration from /djproject/mysite/uwsgi.ini
5月 25 16:02:06 ZPY systemd[1]: PID file /run/uwsgi.pid not readable (yet?) after start.
5月 25 16:02:06 ZPY systemd[1]: Started uwsgi service.
4、安装nginx
这里采用yum安装nginx:
yum -y install nginx
配置nginx与uwsgi代理:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}