我做了一些搜索,没有看到任何类似的问题。
我有一个应该每五分钟运行一次的工作。
一次应该只运行一项作业。
如果程序运行时间超过 5 分钟,则应立即重新启动,而不是等待。
大多数情况下,工作会在一分钟内完成,偶尔它必须完成可能需要长达 20 分钟的事情。
我目前将此作业作为 systemd 服务运行,该作业是一个 shell 脚本,它在循环中调用实际程序,并在迭代之间休眠(5 分钟 - 上次运行时间)。它工作得很好。
#!/bin/sh
#
# Sample executable repeat-loop
#
# Run my job in a loop. If it takes less than max_delay seconds
# to run, sleep until it's time to repeat. If, for some reason, it took longer, just start
# over again immediately.
max_delay=300 # maximum delay between runs
# Don't allow multiple copies of this script to run
[ "${FLOCKER}" != "$0" …Run Code Online (Sandbox Code Playgroud) systemd ×1