Django + gunicorn + systemd 问题
Django + gunicorn + systemd problems
我正在尝试使用 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'
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
我运行宁 CentOS7 Python 3.4 和 gunicorn 19.4.5
提前致谢!
已解决,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
我正在尝试使用 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'
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
我运行宁 CentOS7 Python 3.4 和 gunicorn 19.4.5 提前致谢!
已解决,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