uWSGI 在 Ubuntu 16.04 下不會以 systemd 啟動
我正在將我們的登台和生產伺服器從 Ubuntu 12.04 遷移到 16.04,這有點痛苦。我正在測試暫存遷移,它大部分都在工作,除了讓 uWSGI 在 systemd 下啟動(它以前在 Upstart 下執行良好)。這沒有問題:
uwsgi --ini /etc/uwsgi/my_wsgi.ini
但是執行以下命令不起作用(uWSGI 不會啟動,但不會產生錯誤):
sudo systemctl start uwsgi
我在 /etc/systemd/system/uwsgi.service 中創建了以下服務:
[Unit] Description=uWSGI Service [Service] ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/my_wsgi.ini Restart=always RestartSec=5 KillSignal=SIGQUIT Type=notify NotifyAccess=all [Install] WantedBy=multi-user.target
並且 my_wsgi.ini 具有以下內容:
[uwsgi] # Django-related settings # the base directory (full path) chdir = /path/to/project/hidden # Django's wsgi file module = wsgi # process-related settings # master master = true # maximum number of worker processes processes = 8 # the socket (use the full path to be safe) socket = /path/to/socket/hidden # ... with appropriate permissions - may be needed chmod-socket = 666 # clear environment on exit vacuum = true # Mercilessly kill this worker if it takes longer than this time to reload reload-mercy = 8 # Reload workers after the specified amount of managed requests (avoid memory leaks) max-requests = 5000 # Every request that will take longer than the seconds specified in the harakiri timeout will be dropped and the corresponding worker is thereafter recycled. harakiri = 90 # Log everything and make daemon daemonize = /var/log/uwsgi/my.log # use custom settings file env = DJANGO_SETTINGS_MODULE=settings.staging # set pid file for starting/stopping server pidfile = /path/to/pid/hidden.pid # See https://docs.newrelic.com/docs/python/python-agent-and-uwsgi enable-threads = true single-interpreter = true
執行
systemd-analyze verify uwsgi.service
不返回任何內容並sudo journalctl
返回以下內容:Starting uWSGI Service... [uWSGI] getting INI configuration from /etc/uwsgi/my_wsgi.ini Started uWSGI Service. uwsgi.service: Service hold-off time over, scheduling restart. Stopped uWSGI Service. ... (repeats a few times) ....
我懷疑這
uwsgi.service: Service hold-off time over, scheduling restart.
可能指向問題,但我無法弄清楚。
uwsgi文件明確指出:
注意:除非您知道自己在做什麼,否則不要將皇帝(或主人)守護起來!!!
不幸的是,你在不知道自己在做什麼的情況下將皇帝妖魔化了。從你的問題:
# Log everything and make daemon daemonize = /var/log/uwsgi/my.log
問題是 uwsgi 是 systemd 感知的,並且 systemd 單元告訴 systemd 當 uwsgi 準備好開始處理請求時,uwsgi 將通知 systemd。預設情況下,uwsgi 在 systemd 系統上以這種模式啟動,除非你告訴它守護程序。在這種情況下,uwsgi不會與 systemd 對話。這就是為什麼 systemd 等待了一段時間,最終放棄等待 uwsgi 告訴 systemd 準備好了。
文件建議您不要讓 uwsgi 守護程序並直接記錄到文件,而是讓它記錄到其預設的標準錯誤,並讓 systemd 拾取日誌並記錄它們。如果您最終將日誌記錄發送到其他地方,例如 ELK 堆棧,您將需要這樣做。例如:
[Service] StandardError=syslog
或者,您可以直接從 uwsgi 登錄而無需守護程序。
logto = /var/log/uwsgi/my.log