在 sysd 下为 docker 服务实施看门狗

Implementing watchdog for docker services under sysd

我目前正在做一个 docker 项目,我需要在其中实施看门狗。由于 Docker 容器最终 运行 作为 Docker 守护进程的子进程,它们位于与服务不同的 cgroup 中,sd_notify 事件将不会被处理系统文件。为此,我偶然发现了 https://github.com/coreos/sdnotify-proxy。 通常我会添加看门狗,

[Unit]
Description=My Little Daemon
Documentation=man:mylittled(8)

[Service]
ExecStart=/usr/bin/mylittled
WatchdogSec=30s
Restart=on-failure
StartLimitInterval=5min
StartLimitBurst=4
StartLimitAction=reboot-force

但是用sdnotify-proxy应该怎么实现呢?我对此完全是新手。任何帮助将不胜感激。

用法是:

sdnotify-proxy /path/to/unix-sock cmd ...

unix-sock 用于将 sd_notify 命令从您的进程代理到 systemd。要将它与 Docker 一起使用,我们假设您的 Docker 图像名为 mylittled。您的服务文件将包含:

[Service]
ExecStart=/path/to/sdnotify-proxy /run/mylittled-sd.sock /usr/bin/docker run \
    --volume=/run/mylittled-sd.sock:/run/mylittled-sd.sock \
    --env=NOTIFY_SOCKET=/run/mylittled-sd.sock \
    mylittled

有关示例用法,请参阅 https://github.com/coreos/coreos-overlay/blob/master/app-admin/flannel/files/flanneld.service

如果您使用的是 CoreOS:虽然此实用程序当前包含在我们的映像中(到 运行 flannel),但它被放置在 /usr/libexec 中以不公开它以供一般使用。以后可能会从图片中删除。