配置gunicorn没有virtualenv

时间:2017-06-28 21:58:48

标签: django gunicorn digital-ocean

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

当我尝试启动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.

2 个答案:

答案 0 :(得分:2)

您可以通过输入

找到gunicorn安装的路径
which gunicorn

对我来说(定期安装)此返回

/usr/local/bin/gunicorn

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

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

答案 1 :(得分:1)

很容易看出Gunicorn不会在没有ExecStart指令的情况下启动,没有什么可以运行,所以服务只是返回。

如果您的Gunicorn安装在Virtualenv内并不重要,您的Gunicorn呼叫的第一个参数应该是通往wsgi.py模块的application变量的路径。

假设wsgy.py文件位于/root/revamp/my_project/

你的Gunicorn电话应该是:

gunicorn my_project.wsgi:application ...

其中my_project是包含__init__.py文件的模块名称(包含wsgi.py文件的文件夹),并且还应包含settings.py文件。

如果你没有将它指向有效的WSGI python应用程序,那么Gunicorn就不会开始......