【发布时间】:2021-01-04 18:20:28
【问题描述】:
我们需要监控并在 gUnicorn/Django 应用出现故障时尝试重新启动它。我们正在使用 gunicorn 20.0.4。
我的以下 nrs.service 在 systemd 上运行良好。我试图弄清楚是否可以将 systemd 的看门狗功能与 gUnicorn 集成。查看源代码,我看不到任何调用 sd_notify("WATCHDOG=1") 的地方,所以我认为不,gunicorn 不知道如何让 systemd 知道它已启动(它调用 sd_notify("READY =1...") 在启动时,但在其运行循环中没有发送信号表明它仍在运行)
这里是 nrs.service 文件。我已经注释掉了看门狗变量,因为它显然会在它启动后不久将我的服务发送到失败状态。
[Unit]
Description=Gunicorn instance to serve NRS project
After=network.target
[Service]
WorkingDirectory=/etc/nrs
Environment="PATH=/etc/nrs/bin"
ExecStart=/etc/nrs/bin/gunicorn --error-logfile /etc/nrs/logs/gunicorn_error.log --certfile=/etc/httpd/https_certificate/nrs.cer --keyfile=/etc/httpd/https_certificate/server.key --access-logfile /etc/nrs/logs/gunicorn_access.log --capture-output --bind=nrshost:8800 anomalyalerts.wsgi
#WatchdogSec=15s
#Restart=on-failure
#StartLimitInterval=1min
#StartLimitBurst=4
[Install]
WantedBy=multi-user.target
所以 systemd 看门狗正在做它的事情,只是看起来开箱即用的 gunicorn 不支持它。对'monkey-patching'不太熟悉,但我在想如果我们想使用这种监控方法,我将不得不实现一些自定义代码?其他想法只是让 watch 命令检查服务并尝试重新启动它,这可能更容易。
谢谢 杰森
【问题讨论】: