gunicorn.service cannot open WorkingDirectory and the gunicorn executable. I think it's about permissions but I don't know how I can solve it.
Gunicorn.service无法打开WorkingDirectory和Gunicorn可执行文件。我认为这是关于权限的问题,但我不知道如何解决它。
sudo systemctl status gunicorn:
SUDO SYSTEM CTL STATE GONICORN:
Mar 15 12:12:42 ns1.localhost.com systemd[1]: Started gunicorn daemon.
Mar 15 12:12:42 ns1.localhost.com systemd[16439]: gunicorn.service: Changing to the requested working directory failed: No such file or directory
Mar 15 12:12:42 ns1.localhost.com systemd[16439]: gunicorn.service: Failed at step CHDIR spawning /home/radarkes-api/env/bin/gunicorn: No such file or directory
Mar 15 12:12:42 ns1.localhost.com systemd[1]: gunicorn.service: Main process exited, code=exited, status=200/CHDIR
Mar 15 12:12:42 ns1.localhost.com systemd[1]: gunicorn.service: Failed with result 'exit-code'.
/etc/systemd/system/gunicorn.service:
/etc/SYSTEM/SYSTEM/GURICORn.SERVICE:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/radarkes-api/src
ExecStart=/home/radarkes-api/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/radarkes-api/src/core.sock core.wsgi:application
[Install]
WantedBy=multi-user.target
I can run /home/radarkes-api/env/bin/gunicorn manually, this is the output which means I can access the gunicorn executable:
我可以手动运行/home/radarkes-api/env/bin/genicorn,这是输出,这意味着我可以访问genicorn可执行文件:
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.
I tried:
我试过:
- Adding "source /home/radarkes-api/env/bin/activate &&" at the start of ExecStart.
- chmod -R 777 /home/radarkes-api
tree -d -L 2 /home/radarkes-api/:
树-d-L 2/主页/雷达克斯-api/:
radarkes-api/
├── env
│ ├── bin
│ └── lib
└── src
├── api
└── core
How can I solve this?
我怎么才能解决这个问题?
更多回答
Were you able to solve it? if yes please kindly notify. I am also facing the same problem currently.
你能解决这个问题吗?如果是,请告知。我现在也面临着同样的问题。
I solved it but I don't remember how, sorry.
我解决了,但我不记得是怎么解决的,对不起。
I was using an outdated digital ocean article dated from 2016. So i finally solved it by going through this updated article in which the gunicorn setting was simpler and more straightforward: digitalocean.com/community/tutorials/…
我使用的是2016年的一篇过时的数字海洋文章。所以我最终通过阅读这篇更新的文章解决了这个问题,在这篇文章中,黑角兽的设置更简单、更直接:DigitalOcean/Community/Tutorials/…
优秀答案推荐
ExecStart
must be a sub-path of WorkingDirectory
ExecStart必须是WorkingDirectory子路径
in your example /etc/systemd/system/gunicorn.service
will look like this:
在您的示例中,/etc/systemd/system/genicorn.service将如下所示:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/radarkes-api/src
ExecStart=/home/radarkes-api/src/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/radarkes-api/src/core.sock core.wsgi:application
[Install]
WantedBy=multi-user.target
PS:
PS:
- In your case, it's preferable to create a new virtual env instead of moving your existing
env
folder inside of src
one (to avoid paths issues),
- Make sure all your pip3 requirements are available in your
requirements.txt
file,
- Make sure your
.gitignore
includes the new virtual env folder
Then execute:
然后执行:
$ cd /home/radarkes-api/src
$ python3 -m venv MyEnvName
$ echo 'MyEnvName/' >> .gitignore
$ pip3 install -r requirements.txt
更多回答
我是一名优秀的程序员,十分优秀!