美文网首页
Systemd设置进程保护

Systemd设置进程保护

作者: 我要在河边钓一整天的鱼 | 来源:发表于2018-03-05 22:17 被阅读115次

    参考资料

    Systemd 入门教程:实战篇

    配置

    1. /etc/systemd/system 路径下新建xxx.service文件;
    2. 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.pygunicorn的配置路径。

    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的运行结果:

    circus的运行结果

    直接卡在这里不动了,在google无果后选择了上述的方式进行启程gunicorn
    从开始着手学小程序到第一个接口跑起来,总共时间将近两周,所以本文只做搬砖记录。希望大神指点这样做的优劣和更好的方式。


    服务器部署和Python都是刚学如有那个地方不对的请及时告知,万分感谢。

    谢谢观看

    相关文章

      网友评论

          本文标题:Systemd设置进程保护

          本文链接:https://www.haomeiwen.com/subject/skykfftx.html