How to extend the systemd service unit timeout when rebooting the system

How to extend the systemd service unit timeout when rebooting the system.

https://access.redhat.com/solutions/3600381

 SOLUTION IN PROGRESS - 已更新 2019年一月16日02:58 - 

English 

环境

  • Red Hat Enterprise Linux 7

问题

  • A system kills services forcibly at reboot while saving information to the disk.
  • A system doesn't wait for the services to shut down gracefully.

决议

  • The timeout can be extended by modifying JobTimeoutSec= value in the reboot.target.
  • Modify the reboot.target with a text editor. The reboot.target is located in the /usr/lib/systemd/system/reboot.target

Raw

[Unit]
Description=Reboot
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-reboot.service
After=systemd-reboot.service
AllowIsolate=yes
JobTimeoutSec=30min              <<<<< "The default value is 30 minutes. You can increase/decrease this value."  
JobTimeoutAction=reboot-force

[Install]
Alias=ctrl-alt-del.target

  • Please reload systemd with the following command:

Raw

systemctl daemon-reload 

根源

  • More information on how TimeoutStopSec directive works can be found in the man page.

Raw

$man systemd.service

TimeoutStopSec=

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. 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 exended 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)).

诊断步骤

Raw

#systemctl cat reboot.target

# /usr/lib/systemd/system/reboot.target
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Reboot
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-reboot.service
After=systemd-reboot.service
AllowIsolate=yes
JobTimeoutSec=30min
JobTimeoutAction=reboot-force

[Install]
Alias=ctrl-alt-del.target

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值