Sinatra + Thin의 Systemd 서비스가 계속 다시 시작됩니다.

Sinatra + Thin의 Systemd 서비스가 계속 다시 시작됩니다.

Nginx 리버스 프록시 뒤에 있는 씬 서버를 사용하여 실행되는 Sinatra 애플리케이션을 제공하는 시스템을 구축했습니다. 잘 작동하지만 트래픽이 많이 수신되기 때문에 업스트림에 연결할 수 없다는 nginx 오류가 많이 표시됩니다. 서비스를 확인한 후에는 이 서비스가 매우 오랫동안 실행되지 않고 최대 몇 분만 실행된다는 사실을 발견했습니다. 이는 Nginx가 서비스를 다시 시작할 때 여러 번 연결에 실패하는 이유를 설명합니다.

서비스 출력을 살펴보면 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

내가 이해하지 못하는 또 다른 점은 서비스에서 볼 수 있듯이 Sinatra를 시작했지만 출력 --max-conns 15360에서는 최대 연결이 1024로 설정된 것을 볼 수 있다는 것입니다.journalctl

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

무슨 일이 일어났는지 아세요?

참고: 우분투 18.04.4

답변1

응용 프로그램에 오류가 발생하여 다음 ABRT/6 인쇄가 종료됩니다.

pure virtual method called
terminate called without an active exception

이 오류는 일부 외부 C++ 라이브러리와 관련이 있을 가능성이 높습니다.

연결 제한을 늘리려면 다음을 추가해 보세요.LimitNOFILE=15360조직 파일에.

답변2

그래서 Thin 서버 내부에 문제가 있는 것 같은데, Puma로 교체하니 모든 문제가 사라졌습니다.

관련 정보