参考资料
配置
-
/etc/systemd/system
路径下新建xxx.service
文件; -
xxx.service
中添加如下配置:
[Unit]
Description=miniapp process manager
After=syslog.target network.target nss-lookup.target
[Service]
Type=simple
ExecStart=/home/yang/.virtualenvs/ante-miniapps/bin/gunicorn -c /home/yang/app/ante_miniapps/gunicorn_start.py run:app
▽estart=always
RestartSec=5
[Install]
WantedBy=default.target
这个配置的字段不做过多解释,在这篇文章中将的很仔细(Systemd 入门教程:实战篇)。其中配置中/home/yang/.virtualenvs/ante-miniapps/bin/gunicorn
为虚拟环境的gunicorn的路径,/home/yang/app/ante_miniapps/gunicorn_start.py
为 gunicorn
的配置路径。
Systemd命令设置
· sudo systemctl enable xxx.srvice
#将服务加入开机启动项;
· sudo systemctl daemon-reload
# 修改xxx.service
文件后需要重新加载服务;
· sudo systemctl start xxx
# 启动服务
· sudo systemctl stop xxx
# 停止服务
· sudo systemctl restart xxx
# 重启服务
· sudo systemctl status xxx
# 服务状态
总结
服务器是使用的nginx
+ guninorn
的配置,因为我将系统默认的python
版本和使用的版本改成了Python3
所以不能使用Supervisor
进行进程保护。查找出的替代品是circus
,在看过官方文档和google之后circus
的运行结果:
直接卡在这里不动了,在google无果后选择了上述的方式进行启程gunicorn
。
从开始着手学小程序到第一个接口跑起来,总共时间将近两周,所以本文只做搬砖记录。希望大神指点这样做的优劣和更好的方式。
服务器部署和Python都是刚学如有那个地方不对的请及时告知,万分感谢。
谢谢观看