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 -
环境
- 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 thereboot.target
. - Modify the
reboot.target
with a text editor. Thereboot.target
is located in the/usr/lib/systemd/system/reboot.target
[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:
systemctl daemon-reload
根源
- More information on how TimeoutStopSec directive works can be found in the man page.
$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)).
诊断步骤
#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