centos7 配置 uwsgi 系统服务(systemd)

背景生产环境中采用nginx + uwsgi + django 来部署web服务,这里需要实现uwsgi的启动和停止,简单的处理方式可以直接在命令行中启动和kill掉uwsgi服务,但为了更安全、方便的管理uwsgi服务,配置uwsgi到systemd服务中,同时实现开启自启的功能;
另,鉴于supervisor不支持python3,没采用supervisor来管理uwsgi服务;

具体配置方法如下:

step1. 创建配置文件

/etc/systemd/system/server_uwsgi.service  

step2. 填入以下内容

[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服务  

注意事项:

如果uwsgi配置文件中配置了 daemonize=/path/uwsgi.log (uwsgi服务以守护进程运行)  会导致sytemctl启动时多次重启而导致启动失败  需改为 logto=/path/uwsgi.log  

原文出处:segmentfault -> https://segmentfault.com/a/1190000018273695

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。