繁体   English   中英

无法使用Systemd Emperor运行uwsgi .ini文件

[英]Can't run uwsgi .ini file with systemd emperor

我试图将uwsgi.service设置为在Fedora 24的Linode上的Django 1.10的systemd上运行。

/etc/systemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

然后应该调用/etc/uwsgi/emporer.ini

[uwsgi]
emperor = /etc/uwsgi/vassals
uid = www-data
gid = www-data
limit-as = 1024
logto = /tmp/uwsgi.log

然后,我使用一个符号链接,

$ sudo ln -s /home/ofey/djangoForum/django.ini /etc/uwsgi/vassals/

到/home/ofey/djangoForum/django.ini

[uwsgi]
project = djangoForum
base = /home/ofey

chdir = %(base)/%(project)
home = %(base)/djangoenv
module = crudProject.wsgi:application

master = true
processes = 2

socket = 127.0.0.1:3031
chmod-socket = 664
vacuum = true

我已经重新开始了

$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx.service
$ sudo systemctl retart uwsgi.service

最后一条命令给出

Job for uwsgi.service failed because the control process exited with error code. See "systemctl status uwsgi.service" and "journalctl -xe" for details.

$ sudo systemctl status uwsgi.service

给,

● uwsgi.service - uWSGI Emperor
   Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Dec 07 23:56:28 ofeyspi systemd[1]: Starting uWSGI Emperor...
Dec 07 23:56:28 ofeyspi uwsgi[7834]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Main process exited, code=exited, status=1/FAILURE
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Unit entered failed state.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Dec 07 23:56:28 ofeyspi systemd[1]: Stopped uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Start request repeated too quickly.
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.

我不知道为什么uwsgi.service无法运行。

当我不使用systemd而是使用uwsgi时,

$ sudo --ini django.ini

RuntimeDirectory=uwsgi systemd文档建议将RuntimeDirectory=uwsgi添加到您的服务文件中。 尝试添加。

还要检查/tmp/uwsgi.log以查看是否在其中生成了任何日志记录。

造成这种情况的最可能原因是皇帝无法:

  1. 创建.pid文件以写入processID;
  2. 为vassal创建unix-socket文件(似乎不是您的情况,因为您使用的是:3031 port);
  3. 写入由--logto选项指定的日志文件(在您的情况下为/tmp/uwsgi.log )。

当这些文件中的任何一个存在并且由另一个用户(最有可能是root)拥有或位于启动服务的用户无法写入的目录中时,通常会发生这种情况。

Systemd的状态日志在此主题上不是很有帮助。 因此,识别情况的最快方法是从systemd的服务而不是root用户运行ExecStart命令并查看输出:

$ /home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini

如果输出显示问题是权限,请尝试以下操作。

正如已经建议的那样,由于您将代表www-data用户运行服务器,因此请确保您具有:

[Service]
User=www-data
Group=www-data
RuntimeDirectory=uwsgi

在您的systemd单元配置中。 然后,通过将.pid文件和​​unix-socket文件(如果有)创建到该目录下(即/ run / uwsgi下),方法是将其添加到vassals .ini文件中:

runtime_dir = /run/uwsgi
pidfile=%(runtime_dir)/%n.pid

# if you prefer using unix-socket instead of a port
socket = %(runtime_dir)/%n.sock

# trying to chmod-socket is useless with a port, by the way
chmod-socket    = 664

给定示例中的%n变量表示附庸的.ini文件名,不带扩展名(请参见此处完整列表 )。

最后,确保在Emperor和--logto的配置中指定的--logto文件是可写的。

请注意,如果以root用户身份运行uwsgi --ini /etc/uwsgi/emperor.ini ,然后以ctrl + D终止procecc,它将使上述临时文件由root拥有拥有 ,这将阻止其他所有者(例如www-data )从写入它们开始,直到删除文件或再次chown/chmod它们为止。

注释掉KillSignal = SIGQUIT

它可能会导致问题,请参见http://uwsgi-docs.readthedocs.io/en/latest/Systemd.html

也导致Centos 7出现问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM