systemd 退出代码 EXIT_FDS 是什么意思?

systemd status我停止服务后收到此消息:

Actice: failed (Result: exit-code) <...> Main PID: 4747 (code=exited, status=202/FDS)

状态 FDS 在文档中定义如下:

202 EXIT_FDS 无法关闭不需要的文件描述符,或调整传递的文件描述符。

启动服务正常,没有错误报告systemd status

问题

  1. EXIT_FDS 更具体的含义是什么?
  2. 状态码是来自我的应用程序还是来自 systemd 本身?
  3. 我的应用程序打开一个 TCP 套接字,它在停止时不会关闭。是这个原因吗?
  4. 如果是这样,我可以让 systemd 忽略延迟套接字而不将其报告为错误吗?

细节

完整的状态消息:

tool-user@tool-box:~$ systemctl status tool.service
● tool.service - Tool application
   Loaded: loaded (/home/tool-user/tool.service; linked; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2022-02-07 14:14:46 CET; 3s ago
  Process: 4758 ExecStop=/bin/bash -c tool-stop && while ps -p $MAINPID >/dev/null
  Process: 4601 ExecStart=/bin/bash -c tool-start (code=exited, status=0/SUCCESS)
 Main PID: 4747 (code=exited, status=202/FDS)

Feb 07 14:14:31 tool-box systemd[1]: Starting Tool application...
Feb 07 14:14:32 tool-box bash[4601]: Server started on port 44680
Feb 07 14:14:32 tool-box systemd[1]: Started Tool application.
Feb 07 14:14:44 tool-box systemd[1]: Stopping Tool application...
Feb 07 14:14:45 tool-box systemd[1]: tool.service: Main process exited, code=exited, status=202/FDS
Feb 07 14:14:46 tool-box systemd[1]: tool.service: Failed with result 'exit-code'.
Feb 07 14:14:46 tool-box systemd[1]: Stopped Tool application.

服务定义文件如下所示:

[Unit]
Description=Tool application
# Standard dependencies for web server
After=network.target remote-fs.target nss-lookup.target httpd-init.service

[Service]
Type=forking
Restart=on-failure
RestartSec=10
ExecStart=/bin/bash -c 'toolStart'
ExecStop=/bin/bash -c 'toolStop && while ps -p $MAINPID >/dev/null 2>&1; do sleep 1; done'
User=tool-user
StandardOutput=syslog
StandardError=syslog
TimeoutStopSec=60

[Install]
WantedBy=multi-user.target

操作系统:Ubuntu 18.04 服务器,在 Windows 10 上的 VirtualBox 中运行。

tool-user@tool-box:~$ uname -a
Linux tool-box 4.15.0-166-generic #174-Ubuntu SMP Wed Dec 8 19:07:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
电信

由于该服务具有PID 4758 Type=forkingExecStart并且您要询问的退出代码与主 PID 4747 一起列出,因此我们可以得出结论,它systemd管理了fork()一个子进程,该子进程然后成功execve()执行了 ExecStart 进程,因此 systemd 表- 特定的退出代码不适用于此处。

systemd如果错误来自实际的子进程,fork()则将应用 systemd 特定的退出代码表execve():具体而言,错误 202 将意味着例如在服务定义中实现StandardInput=StandardOutput=StandardError=指令时出现问题。但由于ExecStart特别报告 PID 4601 并以 退出status=0/SUCCESS,这不是这里发生的情况。ExecStop执行为 PID 4758,所以它也不是来自那个。

状态码 202 来自应用程序的“主进程”(PID 为 4747 的那个),它表示应用程序开发人员想要的任何含义。

延迟的 TCP 套接字不是原因:由于您的应用程序进程死亡,内核将清除它可能拥有的任何延迟的套接字。

当然,如果应用程序没有使用 SO_REUSEADDR 套接字选项,则可能无法立即重新启动应用程序并让它使用相同的端口号,直到延迟套接字的 TIME_WAIT 过期......但这不是 systemd 的问题;这是应用程序必须自己处理的事情。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章