我正在DigitalUcean服务器上创建systemd service file
,该服务器具有ubuntu 18和NGINX作为Web服务器。
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
应该使用哪个用户?我该如何纠正此错误?
Edit2
正如奥利弗(Oliver)在评论中所说,我执行:
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.