【问题标题】:uwsgi broken pipe when running it as systemd serviceuwsgi作为systemd服务运行时损坏的管道
【发布时间】:2016-03-15 17:00:49
【问题描述】:

我正在使用 python 2.7.11 在 conda 虚拟环境中运行 uwsgi/flask python 应用程序。

我正在从 CentOS 6 迁移到 CentOS 7,并希望利用 systemd 将我的应用程序作为服务运行。如果我手动调用我的应用程序的启动脚本(sh start-foo.sh),一切(配置和代码)都可以正常工作,但是当我尝试将其作为 systemd 服务(sudo systemctl foo start)启动时,它会启动应用程序但随后立即失败以下错误:

WSGI app 0 (mountpoint='') ready in 8 seconds on interpreter 0x14c38d0 pid: 3504 (default app)
mountpoint  already configured. skip.
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3504)
emperor_notify_ready()/write(): Broken pipe [core/emperor.c line 2463]
VACUUM: pidfile removed.

这是我的 systemd 单元文件:

[Unit]
Description=foo

[Service]
ExecStart=/bin/bash /app/foo/bin/start-foo.sh
ExecStop=/bin/bash /app/foo/bin/stop-foo.sh

[Install]
WantedBy=multi-user.target

不确定是否有必要,但这是我的 uwsgi 皇帝和附庸配置:

皇帝

[uwsgi]
emperor = /app/foo/conf/vassals/
daemonize = /var/log/foo/emperor.log

封臣

[uwsgi]
http-timeout = 500
chdir = /app/foo/scripts
pidfile = /app/foo/scripts/foo.pid
#socket = /app/foo/scripts/foo.soc
http = :8888
wsgi-file = /app/foo/scripts/foo.py
master = 1
processes = %(%k * 2)
threads = 1
module = foo
callable = app
vacuum = True
daemonize = /var/log/foo/uwsgi.log

我尝试通过 Google 搜索此问题,但似乎找不到任何相关内容。我怀疑这与在虚拟环境中运行 uwsgi 并使用 systemctl 启动它有关。我是 systemd n00b,所以如果我在我的 Unit 文件中做错了什么,请告诉我。

这不是一个阻止程序,因为我仍然可以通过手动执行脚本来启动/停止我的应用程序,但我希望能够将它作为服务运行并在启动时使用 systemd 自动启动它。

【问题讨论】:

  • 尝试将TypeWorkingDirectory 添加到service 单元文件的[Service] 部分,使用Type=simpleWorkingDirectory=/app/foo/bin/
  • @Noelkd,没有帮助...同样的问题。

标签: python linux uwsgi systemd conda


【解决方案1】:

按照 uwsgi 文档中关于设置 systemd 服务的说明 here 解决了该问题。

这是我改变的:

从皇帝和附庸配置中删除了daemonize

从上面的链接中获取单元文件并稍作修改以使用我的应用程序

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

[Service]
ExecStart=/app/foo/bin/uwsgi /app/foo/conf/emperor.ini
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 2020-03-06
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2017-08-01
    • 2019-08-19
    相关资源
    最近更新 更多