gunicorn.service:在步骤 CHDIR 生成时失败 */env/bin/gunicorn:没有这样的文件或目录

问题描述 投票:0回答:1

gunicorn.service 无法打开WorkingDirectory 和gunicorn 可执行文件。我认为这是关于权限的问题,但我不知道如何解决它。

sudo systemctl状态gunicorn:

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:

[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

我可以手动运行/home/radarkes-api/env/bin/gunicorn,这是输出,这意味着我可以访问gunicorn可执行文件:

usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.

我试过:

  • 在 ExecStart 的开头添加“source /home/radarkes-api/env/bin/activate &&”。
  • chmod -R 777 /home/radarkes-api

tree -d -L 2 /home/radarkes-api/:

radarkes-api/
├── env
│   ├── bin
│   └── lib
└── src
    ├── api
    └── core

我该如何解决这个问题?

ubuntu gunicorn systemctl
1个回答
0
投票

ExecStart
必须是
WorkingDirectory

的子路径

在您的示例中

/etc/systemd/system/gunicorn.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:

  1. 在您的情况下,最好创建一个新的虚拟环境,而不是将现有的
    env
    文件夹移动到
    src
    文件夹内(以避免路径问题),
  2. 确保您的所有 pip3 要求在您的
    requirements.txt
    文件中可用,
  3. 确保您的
    .gitignore
    包含新的虚拟环境文件夹

然后执行:

$ cd /home/radarkes-api/src
$ python3 -m venv MyEnvName
$ echo 'MyEnvName/' >> .gitignore
$ pip3 install -r requirements.txt

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.