systemd:24 小时后自动重启服务?
systemd: automatically restart service after 24 hours?
systemd里有设置吗
自动重启服务
例如之后24 小时?
或者实现此类功能的最佳解决方法是什么?
背景:我的长期 运行 网络收集和存储到数据库代码中有一个难以识别的缺陷。它确实工作了 10 或 20 天,然后突然停止,直到我们手动重置它。即使是过多的日志记录也让我不知道问题到底出在哪里。当然,我更愿意解决根本问题,但是(出于经济原因)蛮力终止并重启可能也能解决问题。
编辑:我似乎终于找到了真正的缺陷 - 我没有(不能)设置超时的互联网查询(因为 read_json 函数不允许该选项)。现在已经通过 socket.setdefaulttimeout(...) 解决了它 - 我希望这将解决这个不常见的停机问题。
谢谢你的帮助!
Systemd 有一个内置的看门狗功能,请参阅此 link 了解更多信息。
然而,您必须修补您的软件才能发送 sd_notify 事件,因此看门狗知道您的软件仍然存在。
来自1:
First of all, to make software watchdog-supervisable it needs to be
patched to send out "I am alive" signals in regular intervals in its
event loop. Patching this is relatively easy. First, a daemon needs to
read the WATCHDOG_USEC= environment variable. If it is set, it will
contain the watchdog interval in usec formatted as ASCII text string,
as it is configured for the service. The daemon should then issue
sd_notify("WATCHDOG=1") calls every half of that interval. A daemon
patched this way should transparently support watchdog functionality
by checking whether the environment variable is set and honouring the
value it is set to.
一种更加快速和肮脏的方法是设置一个 cron-job,它每 24 小时终止一次进程并重新启动您的服务。
我想您的要求与以下问题相同。
我希望这能回答你的问题。
systemd里有设置吗 自动重启服务 例如之后24 小时?
或者实现此类功能的最佳解决方法是什么?
背景:我的长期 运行 网络收集和存储到数据库代码中有一个难以识别的缺陷。它确实工作了 10 或 20 天,然后突然停止,直到我们手动重置它。即使是过多的日志记录也让我不知道问题到底出在哪里。当然,我更愿意解决根本问题,但是(出于经济原因)蛮力终止并重启可能也能解决问题。
编辑:我似乎终于找到了真正的缺陷 - 我没有(不能)设置超时的互联网查询(因为 read_json 函数不允许该选项)。现在已经通过 socket.setdefaulttimeout(...) 解决了它 - 我希望这将解决这个不常见的停机问题。 谢谢你的帮助!
Systemd 有一个内置的看门狗功能,请参阅此 link 了解更多信息。
然而,您必须修补您的软件才能发送 sd_notify 事件,因此看门狗知道您的软件仍然存在。
来自1:
First of all, to make software watchdog-supervisable it needs to be patched to send out "I am alive" signals in regular intervals in its event loop. Patching this is relatively easy. First, a daemon needs to read the WATCHDOG_USEC= environment variable. If it is set, it will contain the watchdog interval in usec formatted as ASCII text string, as it is configured for the service. The daemon should then issue sd_notify("WATCHDOG=1") calls every half of that interval. A daemon patched this way should transparently support watchdog functionality by checking whether the environment variable is set and honouring the value it is set to.
一种更加快速和肮脏的方法是设置一个 cron-job,它每 24 小时终止一次进程并重新启动您的服务。
我想您的要求与以下问题相同。
我希望这能回答你的问题。