【问题标题】:Django + gunicorn + systemd problemsDjango + gunicorn + systemd 问题
【发布时间】:2016-07-24 12:44:52
【问题描述】:

我正在尝试使用 systemd 为我的 django 项目设置 gunicorn,但它无法加载我项目的另一个库。

File "/home/ubuntu/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
gunicorn[6043]: return _bootstrap._gcd_import(name[level:], package, level)
gunicorn[6043]: ImportError: No module named 'templates'

模板是项目的另一部分,位于单独的目录中。如果我尝试在我的$PYTHONPATH 中运行没有/home/ubuntu/templates/ 的站点,我会得到同样的错误,我已经在我的systemd 单元文件中添加了pythonpath,但它没有做任何事情。

我可以用这个命令成功运行 gunicorn:

/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083

但是我在 systemd 中失败了

系统单元文件

[Unit]
Description="Site"
After=network.target

[Service]
PIDFile=/tmp/pid-gunicorn
User=ubuntu
Group=users
Environment=PYTHONPATH='/home/ubuntu/templates/'
WorkingDirectory=/home/ubuntu/gfa-apps/
ExecStart=/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083
PrivateTmp=true
Type=forking

[Install]
WantedBy=multi-user.target

我正在使用 Python 3.4 和 gunicorn 19.4.5 运行 CentOS7 提前致谢!

【问题讨论】:

    标签: python django gunicorn systemd


    【解决方案1】:

    解决了,systemd 单元文件中的 Environment var 不应该有引号。

    [Unit]
    Description="Site"
    After=network.target
    
    [Service]
    PIDFile=/tmp/pid-gunicorn
    User=ubuntu
    Group=users
    Environment=PYTHONPATH=/home/ubuntu/templates/
    WorkingDirectory=/home/ubuntu/gfa-apps/
    ExecStart=/home/ubuntu/venv/bin/gunicorn --pid /tmp/pid-gunicorn site_gfa.wsgi:application -b 0.0.0.0:8083
    PrivateTmp=true
    Type=forking
    
    [Install]
    WantedBy=multi-user.target
    

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 2014-09-14
      • 2016-09-12
      • 2018-02-09
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2021-01-04
      • 2021-01-02
      相关资源
      最近更新 更多