打开接口时,是否运行/etc/network/if-up.d中的每个脚本?


12

启用网络接口后,/ etc / network / if-up.d中的所有脚本都运行吗?

如果是这样,则interfaces文件中的post-up命令是什么?


1
通常,执行所有“ .d”文件夹内容。其中一些实际上需要文件扩展名为 .sh”。所有文件都应该是可执行的。
kolypto

Answers:


14

是的,通常会运行任何标记为可执行并放置在该文件夹中的脚本。由于使用了运行部件,因此文件确实限于一组特定的名称。

post-up做同样的事情使用up。将脚本放在if-up.d中与使用a post-up指向其他地方的脚本或命令相同。通常,当您只需要为单个界面运行单个命令时,便会使用up | post-up。当您遇到更复杂的事情时,可以创建一个脚本。

人机界面

...
up command

post-up command
      Run  command  after  bringing the interface up.  If this command
      fails then ifup aborts, refraining from marking the interface as
      configured  (even  though it has really been configured), prints
      an error message, and exits with status 0.   This  behavior  may
      change in the future.
...
There  exists  for  each  of  the  above  mentioned options a directory
/etc/network/if-<option>.d/ the scripts in which are run (with no argu-
ments) using run-parts(8) after the option itself has been processed.

人跑零件

run-parts  runs  all  the  executable  files  named  within constraints
described below,

If  the  --lsbsysinit  option  is not given then the names must consist
entirely of upper and lower  case  letters,  digits,  underscores,  and
hyphens.
...
Files are run in the lexical sort  order  of  their  names  unless  the
--reverse  option  is given, in which case they are run in the opposite
order.

1
因此,如果您希望仅在接口启动后才运行脚本,并且需要准备if-up.d文件夹中的内容,则必须将其命名,以便在您需要操作命令后按词法顺序排列,或放入另一个目录并通过post-up命令运行。听起来对吗?
Spig

1
是的,我相信。
Zoredache

1
如此详尽的答案。即使十年后,仍然可以提供洞察力。
Xofo

您必须真正通读运行部件手册页才能识别,即使使用.sh扩展名的文件名正确的脚本也将无法运行。Quote:“ ...如果有关于因点而跳过脚本的任何信息,将大有帮助。我浪费了大量时间进行故障排除...语句'...名称必须完全由大写和小写组成字母,数字,下划线和连字符。” 还不够。我读了两次,没有帮助我理解问题所在。应该明确地写出,带点的脚本将被跳过。”
ChrisW

此“错误”在Debian中是“无法修复”:运行部件不会运行带有sh扩展bug的
ChrisW
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.