參考資料
配置
-
/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
這個(gè)配置的字段不做過(guò)多解釋隆判,在這篇文章中將的很仔細(xì)(Systemd 入門教程:實(shí)戰(zhàn)篇)剔应。其中配置中/home/yang/.virtualenvs/ante-miniapps/bin/gunicorn
為虛擬環(huán)境的gunicorn的路徑厉斟,/home/yang/app/ante_miniapps/gunicorn_start.py
為 gunicorn
的配置路徑欧聘。
Systemd命令設(shè)置
· sudo systemctl enable xxx.srvice
#將服務(wù)加入開(kāi)機(jī)啟動(dòng)項(xiàng);
· sudo systemctl daemon-reload
# 修改xxx.service
文件后需要重新加載服務(wù);
· sudo systemctl start xxx
# 啟動(dòng)服務(wù)
· sudo systemctl stop xxx
# 停止服務(wù)
· sudo systemctl restart xxx
# 重啟服務(wù)
· sudo systemctl status xxx
# 服務(wù)狀態(tài)
總結(jié)
服務(wù)器是使用的nginx
+ guninorn
的配置捂蕴,因?yàn)槲覍⑾到y(tǒng)默認(rèn)的python
版本和使用的版本改成了Python3
所以不能使用Supervisor
進(jìn)行進(jìn)程保護(hù)顽铸。查找出的替代品是circus
茁计,在看過(guò)官方文檔和google之后circus
的運(yùn)行結(jié)果:
直接卡在這里不動(dòng)了,在google無(wú)果后選擇了上述的方式進(jìn)行啟程gunicorn
谓松。
從開(kāi)始著手學(xué)小程序到第一個(gè)接口跑起來(lái)星压,總共時(shí)間將近兩周,所以本文只做搬磚記錄鬼譬。希望大神指點(diǎn)這樣做的優(yōu)劣和更好的方式娜膘。
服務(wù)器部署和Python都是剛學(xué)如有那個(gè)地方不對(duì)的請(qǐng)及時(shí)告知,萬(wàn)分感謝优质。
謝謝觀看