django - 在没有 virtualenv 的情况下配置 Gunicorn

标签 django gunicorn digital-ocean

我正在设置一个没有 virtualenv 的 django 站点,我正在关注 digital ocean's guide设置一直进展顺利,直到我必须设置gunicorn服务实例,该实例有一个字段ExecStart,我在尝试测试时也必须将其删除。

当我尝试启动 Gunicorn 时,出现以下错误

root@samuel-pc:~/revamp# systemctl start gunicorn
Failed to start gunicorn.service: Unit gunicorn.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.service' for details.
root@samuel-pc:~/revamp# 

我的gunicorn服务代码如下:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/root/revamp
#ExecStart=gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/rev$


[Install]
WantedBy=multi-user.target

我设置网站的方式是通过 root 登录,然后将文件夹直接复制到 root 中。 django 应用程序称为 revamp,如果您从文件夹内运行 pwd,您将得到结果 /root/revamp

更新

我已将 execstart 编辑为

ExecStart=gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp.sock revamp.wsgi:application

现在当我运行systemctl status Gunicorn.service时 我明白

● gunicorn.service - gunicorn daemon
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Jun 28 21:48:16 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 28 21:48:16 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 28 21:53:29 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 05:05:06 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 05:05:06 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 05:05:24 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 05:05:24 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

最佳答案

您可以通过输入

找到您的gunicorn安装路径
which gunicorn

对我来说(常规安装)返回了

/usr/local/bin/gunicorn

所以最后你会得到这样的东西:

ExecStart=/usr/local/bin/gunicorn --access-logfile - --workers 3 [...]

关于django - 在没有 virtualenv 的情况下配置 Gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44813210/

相关文章:

python - 更改 Django 应用程序名称时迁移历史不一致

django - 获取 pkg_resources.DistributionNotFound : The 'supervisor==3.2.0' distribution was not found and is required by the application?

docker - 如何配置 NGINX 以从 UNIX 套接字服务 ASGI?

Django从日期时间开始按日期分组

python - Django 并发 get_or_create

node.js - 将 Nginx 设置为 Nodejs 和 Django 的代理

node.js - 将 htaccess 添加到 Ghost 项目

ssl - 如何通过 CloudFlare FREE SSL 使用 Digitalocean Spaces 子域?

terraform - 如何在 Terraform 资源循环中使用非唯一键创建唯一资源

django 中的 css javascript 图像