systemd - Puma systemd 重新启动超时并且似乎失败,尽管实际上已经成功

标签 systemd puma

我们有一个 systemd 服务,根据建议的配置 here 来管理 Puma 进程。 .

虽然看起来运行良好,但重新启动超时,因此看起来失败,即使它们是成功的。如何调试这一类问题? systemd 期望它没有得到什么?

$ systemctl restart puma
Job for puma.service failed because a timeout was exceeded.
See "systemctl status puma.service" and "journalctl -xe" for details.

然而:

$ systemctl status puma.service
● puma.service - Puma HTTP Server
     Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
     Active: activating (start) since Tue 2021-08-17 16:21:54 UTC; 30s ago
TriggeredBy: ● puma.socket
   Main PID: 1791114 (bundle)
      Tasks: 40 (limit: 7028)
     Memory: 561.9M
     CGroup: /system.slice/puma.service
             ├─1791114 puma 4.3.8 (unix:///srv/app/shared/tmp/sockets/puma.sock) [20210817160414]
             ├─1791178 puma: cluster worker 0: 1791114 [20210817160414]
             └─1791190 puma: cluster worker 1: 1791114 [20210817160414]

Aug 17 16:21:55 domain.tld bundle[1791114]: [1791114] * Environment: production
Aug 17 16:21:55 domain.tld bundle[1791114]: [1791114] * Process workers: 2
Aug 17 16:21:55 domain.tld bundle[1791114]: [1791114] * Preloading application
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] * Activated unix:///srv/app/shared/tmp/sockets/puma.sock
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] ! WARNING: Detected 2 Thread(s) started in app boot:
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] ! #<Thread:0x0000585fceb5fcf8 /srv/nlr/app/shared/bundle/rub>
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] ! #<Rack::MiniProfiler::FileStore::CacheCleanupThread:0x0000>
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] Use Ctrl-C to stop
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] - Worker 0 (pid: 1791178) booted, phase: 0
Aug 17 16:22:08 domain.tld bundle[1791114]: [1791114] - Worker 1 (pid: 1791190) booted, phase: 0

还有:

    $ journalctl -xe
-- Automatic restarting of the unit puma.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Aug 17 16:24:56 domain.tld audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=puma comm=>
Aug 17 16:24:56 domain.tld audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=puma comm=">
Aug 17 16:24:56 domain.tld systemd[1]: Stopped Puma HTTP Server.
-- Subject: A stop job for unit puma.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A stop job for unit puma.service has finished.
-- 
-- The job identifier is 142665 and the job result is done.
Aug 17 16:24:56 domain.tld systemd[1]: Starting Puma HTTP Server...
-- Subject: A start job for unit puma.service has begun execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit puma.service has begun execution.
-- 
-- The job identifier is 142665.
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] Puma starting in cluster mode...
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] * Version 4.3.8 (ruby 2.7.4-p191), codename: Mysterious Trav>
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] * Min threads: 5, max threads: 16
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] * Environment: production
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] * Process workers: 2
Aug 17 16:24:57 domain.tld bundle[1791690]: [1791690] * Preloading application
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] * Activated unix:///srv/app/shared/tmp/sockets/puma.sock
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] ! WARNING: Detected 2 Thread(s) started in app boot:
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] ! #<Thread:0x000062e706be2490 /srv/app/shared/bundle/rub>
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] ! #<Rack::MiniProfiler::FileStore::CacheCleanupThread:0x0000>
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] Use Ctrl-C to stop
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] - Worker 0 (pid: 1791747) booted, phase: 0
Aug 17 16:25:07 domain.tld bundle[1791690]: [1791690] - Worker 1 (pid: 1791756) booted, phase: 0
  [1]: https://puma.io/puma/file.systemd.html

puma.service:

[Unit]
Description=Puma HTTP Server
After=network.target

Requires=puma.socket

[Service]
Type=notify

WatchdogSec=10

User=app

WorkingDirectory=/srv/app/current

EnvironmentFile=/srv/app/current/.env

ExecStart=/srv/.rbenv/shims/bundle exec --keep-file-descriptors puma -C /srv/app/current/config/puma.rb

Restart=always

[Install]
WantedBy=multi-user.target

puma.socket:

[Unit]
Description=Puma HTTP Server Accept Sockets

[Socket]
SocketUser=app
SocketGroup=app
ListenStream=/srv/app/shared/tmp/sockets/puma.sock

NoDelay=true
ReusePort=true
Backlog=1024

[Install]
WantedBy=sockets.target

最佳答案

答案在于与sd_notify的集成:使用“简单”类型避免了这个问题。毫无疑问,它可以与 sd_notify 一起使用,但这需要额外的配置才能让应用程序与 systemd 通信状态。

所以代替:

Type=notify
WatchdogSec=10

用途:

Type=simple

...除非您也想弄清楚 sd_notify 集成。

关于systemd - Puma systemd 重新启动超时并且似乎失败,尽管实际上已经成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68821051/

相关文章:

unix - 从 C/C++ 应用程序启动 systemd 服务或调用 D-Bus 服务

java - 在 Java 中从环境接收打开的套接字

ruby-on-rails - 无法在 Ubuntu 16.04 上运行 Puma upstart 脚本

ruby-on-rails - rails : Puma server 3 not showing database queries in development

ruby-on-rails - 在 Windows 上安装 Puma 错误

ruby-on-rails - Puma 错误:无法为 "10.0.2.2"端口 3000 分配请求的地址 - bind(2)(Errno::EADDRNOTAVAIL)

networking - 在不重启的情况下重启 systemd-networkd .link 文件

ubuntu - 尝试使用 systemd 在 ubuntu 服务器上运行 apache Airflow

java - 配置 JMX 导出器时 Kafka 无法启动

ruby - Puma 主进程退出回调