您的位置:首页 > 其它

用systemd管理进程时,修改复位超时等待时间

2017-05-19 11:46 393 查看
用systemd管理进程时,系统复位默认等待时间为90s,如果一个进程不能正常结束,则需要倒计时90秒,系统才能复位,立马感到很烦。

来先看看这个90S是在哪里定义的吧,不难发现,这个参数是在下面文件中:

#  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.

#

# Entries in this file show the compile time defaults.

# You can change settings by editing this file.

# Defaults can be restored by simply deleting this file.

#

# See systemd-system.conf(5) for details.

[Manager]

#LogLevel=info

#LogTarget=journal-or-kmsg

#LogColor=yes

#LogLocation=no

#DumpCore=yes

#ShowStatus=yes

#CrashChangeVT=no

#CrashShell=no

#CrashReboot=no

#CPUAffinity=1 2

#JoinControllers=cpu,cpuacct net_cls,net_prio

#RuntimeWatchdogSec=0

#ShutdownWatchdogSec=10min

#CapabilityBoundingSet=

#SystemCallArchitectures=

#TimerSlackNSec=

#DefaultTimerAccuracySec=1min

#DefaultStandardOutput=journal

#DefaultStandardError=inherit

#DefaultTimeoutStartSec=90s

#DefaultTimeoutStopSec=90s

#DefaultRestartSec=100ms

#DefaultStartLimitInterval=10s

#DefaultStartLimitBurst=5

#DefaultEnvironment=

#DefaultCPUAccounting=no

#DefaultBlockIOAccounting=no

#DefaultMemoryAccounting=no

#Defaul
4000
tTasksAccounting=yes

#DefaultTasksMax=512

#DefaultLimitCPU=

#DefaultLimitFSIZE=

#DefaultLimitDATA=

#DefaultLimitSTACK=

#DefaultLimitCORE=

#DefaultLimitRSS=

#DefaultLimitNOFILE=

#DefaultLimitAS=

#DefaultLimitNPROC=

#DefaultLimitMEMLOCK=

#DefaultLimitLOCKS=

#DefaultLimitSIGPENDING=

#DefaultLimitMSGQUEUE=

#DefaultLimitNICE=

#DefaultLimitRTPRIO=

配置文件中的DefaultTimeoutStopSec=90s决定了这个复位超时等待时间,不过接下来会发现两个问题:1、手动修改这个文件后,复位依然需要等待90s,2、编译时生成的镜像目录中/etc/systemd中并没有这个文件。那这两个问题到底是怎么回事呢?推荐看看金步国写的systemd中文手册:http://blog.csdn.net/huashibuliao/article/details/71566770

里面的systemd-system.conf写到:

当作为系统实例运行时, systemd 将会按照 system.conf 配置文件 以及 system.conf.d 配置目录中的指令工作; 当作为用户实例运行时, systemd 将会按照 user.conf 配置文件 以及 user.conf.d 配置目录中的指令工作。 这些配置文件包含了控制 systemd 行为的设置。

默认设置是在编译期间确定的, 所以仅在确实需要修改默认设置的情况下, 才需要使用配置文件。位于 /etc/systemd/ 目录中的初始配置文件, 仅包含了展示选项默认值的注释, 目的在于方便系统管理员查看和直接修改。

如果软件包想要自定义某些默认设置, 那么必须将自定义的配置文件安装到 /usr/lib/systemd/*.conf.d/ 目录中。 /etc/ 目录仅供系统管理员使用。 系统管理员可以利用下面的逻辑来覆盖默认设置: 主配置文件最先被读取, 优先级也最低。 所有 *.conf.d/ 中的配置文件 都会覆盖主配置文件中的设置。 所有 *.conf.d/ 中的配置文件(无论位于哪个目录中), 统一按照文件名的字典顺序处理。 如果在多个配置文件中设置了同一个选项, 那么仅以文件名最靠后(字典顺序)的那一个为准。 为了便于排序,
建议给所有 *.conf.d/ 中的配置文件 都加上两位十进制数字的文件名前缀。

如果系统管理员想要屏蔽 /usr/lib/ 目录中的某个配置文件, 那么最佳做法是在 /etc/ 目录中 创建一个指向 /dev/null 的同名符号链接, 即可彻底屏蔽 /usr/lib/ 目录中的同名文件。

看到大神的这段话,你是不是豁然开朗。我也一样,在大神的指引下,在编译时,我在源码目录/etc/systemd/目录增加文件system.conf,将DefaultTimeoutStopSec这个值改为10s,然后编译最后将该文件安装到/usr/lib/systemd/system.conf.d,最后问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: