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的链接文件。

  • 相关阅读:
    MFC Windows 程序设计>WinMain 简单Windows程序 命令行编译
    AT3949 [AGC022D] Shopping 题解
    CF643D Bearish Fanpages 题解
    CF643C Levels and Regions 题解
    CF241E Flights 题解
    CF671C Ultimate Weirdness of an Array 题解
    CF1592F Alice and Recoloring 题解
    GYM 102452E 题解
    CF494C Helping People 题解
    P5556 圣剑护符
  • 原文地址:https://www.cnblogs.com/sdlyxyf/p/11366833.html
Copyright © 2011-2022 走看看