KillSignal 如何与 systemd 中的 TimeoutStopSec 交互?

How does KillSignal interact with TimeoutStopSec in systemd?

谁能告诉我以下有关 systemd 服务关闭顺序的信息

  1. 如果我指定了 KillSignal=SIGTERM 那么这将如何交互 这个TimeoutStopSec?这是否意味着在关机期间 服务,第一个 SIGTERM 将被发送,如果服务还在 运行 在 TimeoutStopSec 之后发送 SIGKILL (如果 SendSIGKILL 设置为 yes)?我问的是没有指定任何内容的情况 ExecStop.

  2. TimeoutStopSec是否考虑了ExecStop和所有ExecPostStop

这已在 systemd email thread 中得到解答。在下面发布答案

Can someone let me know the following about systemd service shutdown sequence

1.

If I have specified KillSignal=SIGTERM then how does this interact this
TimeoutStopSec ? Does this mean that during shutdown of service, first
SIGTERM will be sent and if the service is still running after
TimeoutStopSec SIGKILL will be sent (if SendSIGKILL is set to yes? I am
asking about the case where nothing is specified in ExecStop.

是的,没错

2.

Does TimeoutStopSec take into account ExecStop and all ExecPostStop?

TimeoutStopSec 适用于每个命令。如果 ExecStopPost 命令失败(或 超时)后续命令不执行,但如果每个命令 几乎需要 TimeoutStopSec 时间,总执行时间将是 接近 ExecStopPost 命令乘以 TimeoutStopSec。

从那个systemd man

This option serves two purposes. First, it configures the time to wait for each ExecStop= command. If any of them times out, subsequent ExecStop= commands are skipped and the service will be terminated by SIGTERM. If no ExecStop= commands are specified, the service gets the SIGTERM immediately. This default behavior can be changed by the TimeoutStopFailureMode= option. Second, it configures the time to wait for the service itself to stop. If it doesn't terminate in the specified time, it will be forcibly terminated by SIGKILL (see KillMode= in systemd.kill(5)). Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass "infinity" to disable the timeout logic. Defaults to DefaultTimeoutStopSec= from the manager configuration file (see systemd-system.conf(5)).

If a service of Type=notify sends "EXTEND_TIMEOUT_USEC=…", this may cause the stop time to be extended beyond TimeoutStopSec=. The first receipt of this message must occur before TimeoutStopSec= is exceeded, and once the stop time has extended beyond TimeoutStopSec=, the service manager will allow the service to continue to stop, provided the service repeats "EXTEND_TIMEOUT_USEC=…" within the interval specified, or terminates itself (see sd_notify(3)).