cronlock: stop overlapping cron jobs with flock (plus timeout and failure webhooks)
说明与用途
cronlock 通过确保单实例、可选超时、日志记录和失败通知来简化 cron 作业管理,降低脚本复杂性。
问题
Cron jobs can overlap if a job runs longer than its schedule, causing resource contention, corrupted data, or runaway processes.
结果
cronlock simplifies cron job management by ensuring single instances, optional timeouts, logging, and failure notifications, reducing script complexity and errors.
工作流
- 1. Install cronlock by copying it to a directory in $PATH and making it executable.
- 2. Use cronlock with desired options: --name, --timeout, --log, --notify, followed by the command to run.
- 3. cronlock acquires an advisory lock with flock -n; if lock is held, it exits 0 and skips execution.
- 4. If a timeout is set, cronlock runs the command via timeout, enforcing the limit.
- 5. cronlock logs start and end timestamps and streams command output to the specified log file.
- 6. If the command exits non‑zero, cronlock POSTs a JSON payload to the provided webhook URL.
- 7. The script exits with the wrapped command’s exit code (or 0 if skipped).
证据
Cron schedules tasks at fixed intervals. If a job runs longer than its interval, the next invocation starts before the previous one finishes.
cronlock ties all of those primitives together in a single, tiny wrapper.
cronlock [--name NAME] [--timeout SECONDS] [--log FILE] [--notify URL] -- COMMAND [ARGS...]
If another backup is still running when the next cron tick fires, cronlock simply exits 0 without starting a second copy.
- 记录日期: 2026-10-14T19:56:05.197Z