Ubuntu systemd服务文件无法执行命令:权限被拒绝

Ubuntu systemd服务文件无法执行命令:权限被拒绝,ubuntu,digital-ocean,systemd,Ubuntu,Digital Ocean,Systemd,我正在DigitalOcean服务器上创建systemd服务文件,该服务器具有ubuntu 18和NGINX作为web服务器 systemd服务文件中的脚本是: [Unit] Description=gunicorn daemon After=network.target [Service] Type=oneshot User=root Group=www-data WorkingDirectory=/var/www/computationalMarketing ExecStart=/var/

我正在DigitalOcean服务器上创建
systemd服务文件
,该服务器具有ubuntu 18和NGINX作为web服务器

systemd服务文件中的脚本是:

[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:无法执行命令:权限被拒绝

应该使用哪个用户?如何更正此错误

Edit2

正如奥利弗在我的评论中所说:

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.

作为root用户,
ls-la/var/www/computationalMarketing/bin/activate的输出是什么?另外,您的脚本中有两次
ExecStart
,确保第一个条目是正确的吗?@Oliver我已编辑了该问题,为您的评论提供了答案。谢谢请尝试
chmod 755/var/www/computationalMarketing/bin/activate
,它没有设置
x
,因此无法执行。@Oliver完成,现在是另一个错误。谢谢,我不确定是什么错误,但我也不确定是否可以先激活virtualenv,然后运行python脚本,希望virtualenv仍然被激活。我会用virtualenv搜索
systemd执行python
,看看其他人在这种情况下会做什么。