我正在设置一个没有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.
答案 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就不会开始......