看门狗为什么不踢?

时间:2015-10-06 09:36:28

标签: python coreos watchdog systemd

我正在尝试在coreos上配置监视程序。 服务是这样的。

[Unit]
Description=Watchdog example service

[Service]
Type=notify
Environment=NOTIFY_SOCKET=/run/%p.sock
Environment=WATCHDOG_USEC=1000000
ExecStartPre=-/usr/bin/docker kill %p
ExecStartPre=-/usr/bin/docker rm %p
ExecStart=/usr/libexec/sdnotify-proxy /run/%p.sock /usr/bin/docker run \
    --env=NOTIFY_SOCKET=/run/%p.sock \
    -v /run:/run \
    --name %p pranav93/test_watchdogged python hello.py
ExecStop=/usr/bin/docker stop %p

WatchdogSec=1

[Install]
WantedBy=multi-user.target

python文件hello.py就像是,

print 'Hello, in hello.py'
print 'ready sending'
x = sd_notifyd({'READY':1})
print str(x)
print 'watchdog sending'
x = sd_notifyd({'WATCHDOG':1})
print str(x)
print os.environ.get('WATCHDOG_USEC', None)
print 'lol, wait now for sometime'
import time
for i in range(3):
    print i
    time.sleep(1)
print 'finished'

虽然我没有向WATCHDOG=1发送sysd ping,但它仍然没有被它停止,服务也没有移动它'失败'状态。它背后的原因是什么? 日志

Oct 06 09:33:19 core-01 systemd[1]: Starting Watchdog example service...
Oct 06 09:33:19 core-01 docker[2779]: watchdogged
Oct 06 09:33:19 core-01 docker[2790]: watchdogged
Oct 06 09:33:19 core-01 sdnotify-proxy[2800]: True
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: ready sending
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: <socket._socketobject object at 0x7fa3cc3c2440>
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: 1
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: watchdog sending
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: <socket._socketobject object at 0x7fa3cc3c2440>
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: 1
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: None
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: lol, wait now for someyime
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: 0
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: 1
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: 2
Oct 06 09:33:22 core-01 sdnotify-proxy[2800]: finished
Oct 06 09:33:22 core-01 docker[2851]: watchdogged
Oct 06 09:33:22 core-01 systemd[1]: Started Watchdog example service.

1 个答案:

答案 0 :(得分:1)

我注意到了一些事情。首先,在程序退出后,行Started Watchdog example service.延迟3秒,表示未收到READY=1。看门狗监控仅在设备“启动”后启动。

另外,尝试使用print >>os.stderr进行日志记录,因为stdout的输出被缓冲,很难看到时间。

你不应该

Environment=NOTIFY_SOCKET=/run/%p.sock
Environment=WATCHDOG_USEC=1000000

因为这些是由systemd设置的。您应该通过--env以及WATCHDOG_USEC传递代理套接字,因为它将“丢失”,否则:

ExecStart=/usr/libexec/sdnotify-proxy /run/%p.sock /usr/bin/docker run \
--env=NOTIFY_SOCKET=/run/%p.sock --env=WATCHDOG_USEC=1000000