背景生產環境中採用nginx + uwsgi + django 來部署web服務,這裏須要實現uwsgi的啓動和中止,簡單的處理方式能夠直接在命令行中啓動和kill掉uwsgi服務,但爲了更安全、方便的管理uwsgi服務,配置uwsgi到systemd服務中,同時實現開啓自啓的功能;
另,鑑於supervisor不支持python3,沒采用supervisor來管理uwsgi服務;python
具體配置方法以下:nginx
step1. 建立配置文件web
/etc/systemd/system/server_uwsgi.service
step2. 填入如下內容django
[Unit] Description=HTTP Interface Server After=syslog.target [Service] KillSignal=SIGQUIT ExecStart=/usr/bin/uwsgi --ini /path/uwsgi.ini Restart=always Type=notify NotifyAccess=all StandardError=syslog [Install] WantedBy=multi-user.target
step3. 將該服務加入到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服務rest
注意事項:code
若是uwsgi配置文件中配置了 daemonize=/path/uwsgi.log (uwsgi服務以守護進程運行) 會致使sytemctl啓動時屢次重啓而致使啓動失敗 需改成 logto=/path/uwsgi.log