cent7下自啟
1、找到uwsgi位置
whereis uwsgi
得到:/usr/local/python3/bin/uwsgi
2.建立配置檔案
cd /etc/systemd/system/
touch server_uwsgi.service
vi server_uwsgi.service
寫入以下:
[Unit]
Description=HTTP Interface Server
After=syslog.target
[Service]
KillSignal=SIGQUIT
ExecStart=/usr/local/python3/bin/uwsgi --ini /root/hnjcy/website/uwsgi.ini
#注意,重點:這個就是剛才第一步得到的uwsgi的路徑,後面這個uwsgi.ini是你自己項目的路徑(這行可以删掉)
Restart=always
Type=notify
NotifyAccess=all
StandardError=syslog
[Install]
WantedBy=multi-user.target
3.如果uwsgi配置檔案中配置了
daemonize=/path/uwsgi.log
(uwsgi服務以守護程序運作)
會導緻sytemctl啟動時多次重新開機而導緻啟動失敗
需改為
logto=/path/uwsgi.log
- 将該服務加入到systemd中
systemctl enable /etc/systemd/system/server_uwsgi.service
然後就可以通過systemctl來控制服務的啟停
systemctl stop server_uwsgi.service 關閉uwsgi服務
systemctl start server_uwsgi.service 開啟uwsgi服務
systemctl restart server_uwsgi.service 重新開機uwsgi服務
感謝連結:https://blog.csdn.net/sinat_41292836/article/details/103764842
不過他沒有說明uwsgi的路徑,可能會影響一部分人導緻錯誤