Ubuntu 如何跟踪 motd 中的“需要系统重启”标志?

And*_*ahl 86 ubuntu

我有几台 Ubuntu 服务器(8.10、9.10)设置为自动安装安全更新。有时这些更新需要重新启动系统,此字符串显示在motd

*** System restart required ***
Run Code Online (Sandbox Code Playgroud)

为了获得有关这些的通知,我计划编写一个 Nagios 测试来监控服务器是否需要重新启动。所以,我的问题:

有没有比解析更好的方法/etc/motd来确定是否需要重新启动?

Dan*_*ley 100

检查 的存在/var/run/reboot-required

  • 注意:对于 debian 系统,除非安装了 `update-notifier-common` 软件包,否则不会创建 `/var/run/reboot-required`。 (17认同)
  • 请注意,[`update-notifier-common`](https://packages.debian.org/search?keywords=update-notifier-common) 已在 Debian Jessie 中删除。[`unattended-upgrades`](https://packages.debian.org/search?keywords=unattended-upgrades) 现在包含一个简单的脚本 `/etc/kernel/postinst.d/unattended-upgrades`,其中 `touch`es文件。[`reboot-notifier`](https://packages.debian.org/search?keywords=reboot-notifier) 是另一个兼容`update-notifier-common`格式的小包。 (7认同)

Ric*_*way 39

生成 motd 需要重启部分的脚本是 /usr/lib/update-notifier/update-motd-reboot-required ,其中包含:

#!/bin/sh -e
#
# helper for update-motd

if [ -f /var/run/reboot-required ]; then
        cat /var/run/reboot-required
fi
Run Code Online (Sandbox Code Playgroud)

您的 nagios 检查可以检查 /var/run/reboot-required 是否存在。

  • +1 用于显示它位于哪个文件中 (2认同)

小智 31

此外,文件“/var/run/reboot-required.pkgs”列出了请求重启的软件包。例如:

$ cat /var/run/reboot-required.pkgs 
linux-image-2.6.32-28-generic
dbus
$
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu Lucid (10.4) 上。


chr*_*and 13

Debian 和 Ubuntu 包可以通过执行帮助脚本触发/var/run/reboot-required*在它们的postinst文件中创建/usr/share/update-notifier/notify-reboot-required

因此,处理重启的“官方”方式由软件包维护者处理。我以前在脚本中通过将启动时间与 /boot 中的 mtimes 进行比较来执行此操作。