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.
我试过:
tree -d -L 2 /home/radarkes-api/:
radarkes-api/
├── env
│ ├── bin
│ └── lib
└── src
├── api
└── core
我该如何解决这个问题?
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:
env
文件夹移动到 src
文件夹内(以避免路径问题),requirements.txt
文件中可用,.gitignore
包含新的虚拟环境文件夹然后执行:
$ cd /home/radarkes-api/src
$ python3 -m venv MyEnvName
$ echo 'MyEnvName/' >> .gitignore
$ pip3 install -r requirements.txt
祝你好运!