systemd timer, 定时任务
Contents
systemd timer, 定时任务
|
|
创建一个服务
|
|
content of foo.service
|
|
再创建一个对应的 timer, /etc/systemd/system/foo.timer
|
|
content of foo.timer
|
|
启用 timer
|
|
http://www.ruanyifeng.com/blog/2018/03/systemd-timer.html
the basic format of Oncalnedar event
|
|
It is divided into 3 parts -
*
To signify the day of the week eg:- Sat,Thu,Mon*-*-*
To signify the calendar date. Which means it breaks down to - year-month-date.2021-10-15
is 15th of October*-10-15
means every year at 15th October*-01-01
means every new year.
*:*:*
is to signify the time component of the calnedar event. So it is - hour:minute:second
[[cron#cron crond crontab linux 定时任务 cronie]]
https://silentlad.com/systemd-timers-oncalendar-(cron)-format-explained
- Every day at 2am,
*-*-* 02:00:00
- every 29 days at 2am,
*-*-* 02:00:00/29
systemd timer 相比 cron 的优点
- 日志更丰富 journald
- 可以设置内存和 CPU 的使用额度
- 任务可以拆分,依赖其他 Systemd 单元,完成非常复杂的任务
Author -
LastMod 2022-07-09