zoukankan      html  css  js  c++  java
  • UbuntuServer1804设置uwsgi自启动服务

    在 Ubuntu 上使用 Nginx+ uWSGI 部署Django项目,在实际生成环境中需要系统自动启动这两项服务,Ubuntu默认自启动Nginx,需要对uwsgi设置为系统自启动。

    Ubuntu1804采用systemctl来管理开机启动的脚本,对于uwsgi服务要设置成系统服务来进行自启动。

    1、首先创建 uwsgi.service 文件 

      目录位置:/etc/systemd/system/

      sudo vim /etc/systemd/system/uwsgi.service  

    [Unit]
    Description=uWSGI server
    After=syslog.target 
    [Service]
    #用户名
    User=user_name
    #项目目录 WorkingDirectory=/home/username/projectname
    #需要的环境变量配置文件 #Environment=/home/username/projectname/env.cfg
    #服务启动的代码,可用which命令查看uwsgi的具体位置User=username ExecStart=/home/username/.local/bin/uwsgi --ini uwsgi.ini
    #用户组 Group=www-data
    [Install]
    #指明会跟随系统启动而启动该服务
    WantedBy=multi-user.target

    2、启动、停止、重启、查看服务命令 :

      sudo systemctl start uwsgi.service

      sudo systemctl stop uwsgi.service

      sudo systemctl restart uwsgi.service

           sudo systemctl status uwsgi.service #查看服务状态,可查看错误信息

    3、加入、关闭系统自启动:

      sudo systemctl daemon-reload

      sudo systemctl enable uwsgi.service

      sudo systemctl disable uwsgi.service

      执行此命令后在/etc/systemd/system/multi-user.target.wants目录下生成uwsgi.sevice的链接文件,

      Ubuntu1804系统的自启动项目均在此目录下。重启系统后,可看到uwsgi服务已启动。

    4、总结:

      1、建立service文件,必须保证文件编辑正确,因为不返回执行结果;注意注释格式(最好去掉),建议使用vi编辑,有的编辑器会带有空格;

      2、建立链接文件或复制文件到/etc/systemd/system/目录中;

      3、通过systemctl enable uwsgi.service命令在/etc/systemd/system/multi-user.target.wants目录下生成uwsgi.sevice的链接文件。

  • 相关阅读:
    hibernate 主键利用uuid生成
    Jquery ui widget开发
    完美解决IE6不支持position:fixed的bug
    rose pipe–一次对http技术的伟大革新实现(54chen乱弹版)
    关于JBoss的Log4j的输出问题
    《rose portal & pipe技术介绍》之《变革:结构&范围》
    click() 方法和mousedown
    BigPipe具体实现细节
    获取汉字首字母,拼音,可实现拼音字母搜索npm jspinyin
    时间戳显示格式为几天前、几分钟前、几秒前vue过滤器
  • 原文地址:https://www.cnblogs.com/sdlyxyf/p/11366833.html
Copyright © 2011-2022 走看看