简体   繁体   English

Sinatra + Thin 的 Systemd 服务不断重启

[英]Systemd service for Sinatra + Thin keeps restarting

I have systemd service for a Sinatra app running with Thin server behind an Nginx reverse proxy.我为在 Nginx 反向代理后面运行瘦服务器的 Sinatra 应用程序提供了 systemd 服务。 It works fine but because it receives a lot of traffic i'm seeing a lot of nginx errors about being unable to connect to upstream.它工作正常,但因为它接收大量流量,我看到很多关于无法连接到上游的 nginx 错误。 Upon inspecting the service i noticed that it never runs for very long, just a few minutes at best which would explain why Nginx can't connect a lot of times (while the service is rebooting).在检查服务后,我注意到它永远不会运行很长时间,最多只运行几分钟,这可以解释为什么 Nginx 无法连接很多次(在服务重新启动时)。

Looking at the output of journalctl for the service i see a lot of this:查看 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.

It looks like the app is getting killed regularly?看起来该应用程序经常被杀死? Why is this happening?为什么会这样?

Here's the service:这是服务:

[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

Another thing i don't understand, as you can see from the service i am starting Sinatra with --max-conns 15360 and yet in the journalctl output i can see the maximum connections are set to 1024:另一件事我不明白,正如您从服务中看到的那样,我正在使用--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

Any idea of what's going on?知道发生了什么吗?

Note: Ubuntu 18.04.4注:Ubuntu 18.04.4

So it seems the problem was within the Thin server, once I replaced it with Puma all problems disappeared.所以看起来问题出在瘦服务器上,一旦我用 Puma 替换它,所有问题都消失了。

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

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