簡體   English   中英

Sinatra + Thin 的 Systemd 服務不斷重啟

[英]Systemd service for Sinatra + Thin keeps restarting

我為在 Nginx 反向代理后面運行瘦服務器的 Sinatra 應用程序提供了 systemd 服務。 它工作正常,但因為它接收大量流量,我看到很多關於無法連接到上游的 nginx 錯誤。 在檢查服務后,我注意到它永遠不會運行很長時間,最多只運行幾分鍾,這可以解釋為什么 Nginx 無法連接很多次(在服務重新啟動時)。

查看 journalctl 的journalctl服務,我看到很多這樣的:

Dec 20 22:09:48 cs2092 systemd[1]: Started My app web site.
Dec 20 22:10:59 cs2092 bundle[11576]: pure virtual method called
Dec 20 22:10:59 cs2092 bundle[11576]: terminate called without an active exception
Dec 20 22:10:59 cs2092 systemd[1]: my-service.service: Main process exited, code=killed, status=6/ABRT
Dec 20 22:10:59 cs2092 systemd[1]: my-service.service: Failed with result 'signal'.
Dec 20 22:10:59 cs2092 systemd[1]: my-service.service: Service hold-off time over, scheduling restart.
Dec 20 22:10:59 cs2092 systemd[1]: my-service.service: Scheduled restart job, restart counter is at 7.
Dec 20 22:10:59 cs2092 systemd[1]: Stopped My app web site.
Dec 20 22:10:59 cs2092 systemd[1]: Started My app web site.
Dec 20 22:11:19 cs2092 bundle[11828]: pure virtual method called
Dec 20 22:11:19 cs2092 bundle[11828]: terminate called without an active exception
Dec 20 22:11:19 cs2092 systemd[1]: my-service.service: Main process exited, code=killed, status=6/ABRT
Dec 20 22:11:19 cs2092 systemd[1]: my-service.service: Failed with result 'signal'.
Dec 20 22:11:19 cs2092 systemd[1]: my-service.service: Service hold-off time over, scheduling restart.
Dec 20 22:11:19 cs2092 systemd[1]: my-service.service: Scheduled restart job, restart counter is at 8.
Dec 20 22:11:19 cs2092 systemd[1]: Stopped My app web site.
Dec 20 22:11:19 cs2092 systemd[1]: Started My app web site.
Dec 20 22:14:28 cs2092 bundle[11968]: pure virtual method called
Dec 20 22:14:28 cs2092 bundle[11968]: terminate called without an active exception
Dec 20 22:14:28 cs2092 systemd[1]: my-service.service: Main process exited, code=killed, status=6/ABRT
Dec 20 22:14:28 cs2092 systemd[1]: my-service.service: Failed with result 'signal'.
Dec 20 22:14:28 cs2092 systemd[1]: my-service.service: Service hold-off time over, scheduling restart.
Dec 20 22:14:28 cs2092 systemd[1]: my-service.service: Scheduled restart job, restart counter is at 9.
Dec 20 22:14:28 cs2092 systemd[1]: Stopped My app web site.
Dec 20 22:14:28 cs2092 systemd[1]: Started My app web site.

看起來該應用程序經常被殺死? 為什么會這樣?

這是服務:

[Unit]
Description=My app web site
Documentation=https://myapp.com
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/www/my-app
Environment="RACK_ENV=production"
ExecStart=/usr/local/bin/bundle exec /usr/local/bin/thin -R /var/www/my-app/config.ru -p 6903 --max-conns 15360 --max-persistent-conns 2048 --threaded --debug start
ExecStop=/usr/local/bin/bundle exec /usr/local/bin/thin -R /var/www/my-app/config.ru -p 6903 stop
ExecReload=/usr/local/bin/bundle exec /usr/local/bin/thin -R /var/www/my-app/config.ru -p 6903 --max-conns 15360 --max-persistent-conns 2048 --threaded --debug restart
Restart=on-failure
User=julien

[Install]
WantedBy=multi-user.target

另一件事我不明白,正如您從服務中看到的那樣,我正在使用--max-conns 15360啟動 Sinatra,但在journalctl output 中,我可以看到最大連接數設置為 1024:

Dec 21 10:24:24 cs2092 bundle[21058]: Starting my-app in production...
Dec 21 10:24:24 cs2092 bundle[21058]: 2021-12-21 10:22:30 +0000 Thin web server (v1.8.1 codename Infinite Smoothie)
Dec 21 10:24:24 cs2092 bundle[21058]: 2021-12-21 10:22:30 +0000 Debugging ON
Dec 21 10:24:24 cs2092 bundle[21058]: 2021-12-21 10:22:30 +0000 Maximum connections set to 1024
Dec 21 10:24:24 cs2092 bundle[21058]: 2021-12-21 10:22:30 +0000 Listening on 0.0.0.0:6903, CTRL+C to stop

知道發生了什么嗎?

注:Ubuntu 18.04.4

所以看起來問題出在瘦服務器上,一旦我用 Puma 替換它,所有問題都消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM