网络关闭前的 Linux 关机/重新启动通知



是否可以在所有网络接口停止之前检测到Linux中的系统关闭/重新启动?我可以处理SIGTERM信号并检查运行级别,但目前网络可能已经关闭。我需要在我的 Python 脚本中使用功能。

在关机(运行级别 0)或重新启动(运行级别 6)时,分别按顺序运行/etc/rc.d/rc0.d//etc/rc.d/rc6.d/中的脚本。 如果你看这些目录,你会看到这样的东西:

lrwxrwxrwx. 1 root root 17 Feb 10  2012 K00ipmievd -> ../init.d/ipmievd
lrwxrwxrwx. 1 root root 16 Feb 25  2013 K01smartd -> ../init.d/smartd
 ...
lrwxrwxrwx. 1 root root 17 Dec 16 13:27 K90network -> ../init.d/network
 ...
lrwxrwxrwx. 1 root root 14 Jul 27  2015 K95rdma -> ../init.d/rdma
lrwxrwxrwx. 1 root root 18 Jul 27  2015 K99cpuspeed -> ../init.d/cpuspeed
lrwxrwxrwx. 1 root root 22 Dec 16 13:28 K99lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx. 1 root root 14 Dec  8  2011 K99rngd -> ../init.d/rngd
lrwxrwxrwx. 1 root root 17 Oct 24  2014 K99sysstat -> ../init.d/sysstat

如果您希望关闭脚本在网络关闭之前运行,请将其放在网络关闭之前。

您可能不想直接操作这些目录,因此请参阅man chkconfig

编辑

我应该补充一点,如果你的Linux足够新,可以systemd那么所有这些都不在窗口。

最新更新