Solution to long shutdown time of Linux operating system

  Recently, when I was studying the Linux operating system, I found that the shutdown time often becomes longer due to an unknown process.
  The system terminal will output: a start job is running for init-scope (1min,30s).
  The reason for this may be that some system services have not started or shut down normally. You can check the system log to troubleshoot. Of course, you can also modify the default system configuration parameters of systemd to reduce the waiting time.

1. System service management Systemd

  When running as a system instance, systemd will work according to the system.conf configuration file and the instructions in the system.conf.d configuration directory; when running as a user instance, systemd will work according to the user.conf configuration file and user.conf. d directives in the configuration directory work. These configuration files contain settings that control the behavior of systemd.

路径:
/etc/systemd/system.conf,/etc/systemd/system.conf.d/*.conf  
/etc/systemd/user.conf,/etc/systemd/user.conf.d/*.conf

2. Solution

1. Modify the system.conf file

vim /etc/systemd/system.conf
修改 DefaultTimeoutStopSec 的值,默认90秒,可以改为5秒,注意去掉前边的#号

DefaultTimeoutStartSec DefaultTimeoutStopSec
sets the maximum time allowed to start/stop a unit, and the interval between stopping and starting when restarting a unit. If only an integer is set without a unit, the unit is seconds. You can also add a time unit suffix after the integer: "ms" (milliseconds), "s" (seconds), "min" (minutes), "h" (hours), "d" (days), "w" ( week) . The default values ​​of DefaultTimeoutStartSec= and DefaultTimeoutStopSec= are 90s.

2. Make the system.conf file effective

  • Restart the server
  • Execute systemctl daemon-reexec

Note: The reason why using daemon-reload is invalid:
  simply using systemctl daemon-reload will not refresh /etc/systemd/system.conf. In other words, daemon-reexec will re-execute the systemd manager and re-read the system configuration file, while daemon-reload will only read the configuration of the service part, excluding the global configuration/systemd/system.conf, which is equivalent to heavyweight daemon-reload.

Guess you like

Origin blog.csdn.net/fish332/article/details/128648468