gpt4 book ai didi

ubuntu - systemd服务文件执行命令失败: Permission denied

转载 作者:行者123 更新时间:2023-12-04 18:24:33 27 4
gpt4 key购买 nike

我正在创建 systemd service file在具有 ubuntu 18 和 NGINX 作为 Web 服务器的 DigitalOcean 服务器上。

位于 systemd service file 的脚本是:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
Type=oneshot
User=root
Group=www-data
WorkingDirectory=/var/www/computationalMarketing
ExecStart=/var/www/computationalMarketing/bin/activate
ExecStart=/var/www/computationalMarketing/computationalMarketing/code/computationalMarketing/gunicorn --access-logfile --bind unix:/tmp/gunicorn.sock computationalMarketing.wsgi:application

[Install]
WantedBy=multi-user.target

错误日志是:
Warning: The unit file, source configuration file or drop-ins of gunicorn.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-07-03 11:57:19 UTC; 10s ago
Process: 8446 ExecStart=/var/www/computationalMarketing/bin/activate (code=exited, status=217/USER)
Main PID: 8446 (code=exited, status=217/USER)

Jul 03 11:57:19 tfm-rius systemd[1]: Starting gunicorn daemon...
Jul 03 11:57:19 tfm-rius systemd[8446]: gunicorn.service: Failed to determine user credentials: No such process
Jul 03 11:57:19 tfm-rius systemd[8446]: gunicorn.service: Failed at step USER spawning /var/www/computationalMarketing/bin/activate: No such process
Jul 03 11:57:19 tfm-rius systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Jul 03 11:57:19 tfm-rius systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jul 03 11:57:19 tfm-rius systemd[1]: Failed to start gunicorn daemon.
root@tfm-rius:/var/www/computationalMarketing/computationalMarketing/code/computationalMarketing#

此错误是否与服务主体中使用的用户有关,或者可能与 execStart 命令之一有关?

编辑:

我将服务机构的用户更改为: www-data
现在,日志错误是: gunicorn.service: Failed to execute command: Permission denied
应该使用哪个用户?我该如何纠正这个错误?

编辑2

正如奥利弗在我执行的评论中所说:
ls -la /var/www/computationalMarketing/bin/activate

输出是:
-rw-r--r-- 1 root root 2243 Jun 28 10:11 /var/www/computationalMarketing/bin/activate

我有两个 ExecStart 由于我必须先激活 virtualenv 然后激活 gunicorn 以允许应用程序工作。

执行后记录: chmod 755 /var/www/computationalMarketing/bin/activate
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2018-07-06 20:39:45 UTC; 9s ago
Process: 3472 ExecStart=/var/www/computationalMarketing/bin/activate (code=exited, status=203/EXEC)
Main PID: 3472 (code=exited, status=203/EXEC)

Jul 06 20:39:45 tfm-rius systemd[1]: Starting gunicorn daemon...
Jul 06 20:39:45 tfm-rius systemd[3472]: gunicorn.service: Failed to execute command: Exec format error
Jul 06 20:39:45 tfm-rius systemd[3472]: gunicorn.service: Failed at step EXEC spawning /var/www/computationalMarketing/bin/activate: Exec format error
Jul 06 20:39:45 tfm-rius systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Jul 06 20:39:45 tfm-rius systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jul 06 20:39:45 tfm-rius systemd[1]: Failed to start gunicorn daemon.

最佳答案

如果 SELinux 正在执行这将导致 Exec/203 错误。
您可以检查并修复如下:

getenforce
tail -f /var/log/audit/audit.log
ls -lZ /var/www/computationalMarketing/bin/activate
semanage fcontext -a -t bin_t /var/www/computationalMarketing/bin/activate
restorecon -vF /var/www/computationalMarketing/bin/activate

关于ubuntu - systemd服务文件执行命令失败: Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51209967/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com