mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-31 04:58:21 +00:00
1 line
9.2 KiB
JSON
1 line
9.2 KiB
JSON
{"pageProps":{"metadata":{"date":"2021-07-19 21:45:47 +08:00","date_modified":"2022-05-22 22:28:49 +08:00","language":"en","source":""},"title":"systemd timers","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"timer-management"},"children":[{"type":"text","value":"Timer management"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/linux.systemd.timers#timer-management"},"children":[{"type":"text","value":"Timer management"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"timedate-formats"},"children":[{"type":"text","value":"Timedate formats"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/linux.systemd.timers#timedate-formats"},"children":[{"type":"text","value":"Timedate formats"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can schedule tasks with timers.\nIf systemd is compiled with the feature, it makes cron unnecessary.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"timer-management"},"children":[{"type":"text","value":"Timer management"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In a fully-installed systemd-enabled system, there are multiple ways to manage your timers.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"While managing them is practically the same as any other units (see "},{"type":"element","tagName":"a","properties":{"href":"/linux.systemd"},"children":[{"type":"text","value":"systemd"}]},{"type":"text","value":"), there are timer-specific ways to manage them easier.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"systemctl list-timers"}]},{"type":"text","value":" is the go-to command that displays an overview of all active timers.\n Just give the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--all"}]},{"type":"text","value":" flag to list all timers including disabled timers.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"systemctl status ${TIMER_UNIT}"}]},{"type":"text","value":" is another way for a specific timer unit.\n It gives the same details as the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"list-timers"}]},{"type":"text","value":" subcommand so you'll rarely use this subcommand in practice.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"timedate-formats"},"children":[{"type":"text","value":"Timedate formats"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"systemd has different ways to denote time.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Timespans denote the duration — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"100 seconds"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"5M 3w"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Timestamps refer to a specific point in time — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"2021-04-02"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"today"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"now"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Calendar events can refer to more than one point of time — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"*-*-4/2"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"Sun,Wed,Fri *-1/2-1/8"}]},{"type":"text","value":".\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"To find more details about time notation, you can view the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"systemd.time.7"}]},{"type":"text","value":" manual page.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's an example of setting a timer for an example backup service.\nThe following timer unit sets it to execute every day at 18:00.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-ini"]},"children":[{"type":"text","value":"[Unit]\nDescription=A deduplicated backup from my computer\nDocumentation=man:borg(1) https://borgbackup.readthedocs.io/\n\n[Timer]\nUnit=borg-backup.service\nOnCalendar=*-*-* 18:00:00\nPersistent=true\n\n[Install]\nWantedBy=graphical.target\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If the timer unit is started, this will trigger "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"borg-backup.service"}]},{"type":"text","value":" from the load path.\nBut you can omit "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"Timer.Unit"}]},{"type":"text","value":" key if you named the timer unit file similarly (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"borg-backup.timer"}]},{"type":"text","value":" with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"borg-backup.service"}]},{"type":"text","value":").\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can find more information about it from the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"systemd.timer.5"}]},{"type":"text","value":" manual page.\nFurthermore, systemd has a testing tool for time with "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"systemd-analyze {timespan,timestamp,calendar}"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"printf \"Timespan example:\\n\"\nprintf \"..............\\n\"\nsystemd-analyze timespan 4000min\nprintf \"..............\\n\\n\"\n\nprintf \"Timestamp example:\\n\"\nprintf \"..............\\n\"\nsystemd-analyze timestamp 2021-07-01\nprintf \"..............\\n\\n\"\n\nprintf \"Calendar example:\\n\"\nprintf \"..............\\n\"\nsystemd-analyze calendar \"*-1/4-5 0/2:00:00\"\nprintf \"..............\\n\\n\"\n"}]}]},{"type":"element","tagName":"div","properties":{"className":["exampe"]},"children":[{"type":"text","value":"Timespan example:\n..............\nOriginal: 4000min\n μs: 240000000000\n Human: 2d 18h 40min\n..............\n\nTimestamp example:\n..............\n Original form: 2021-07-01\nNormalized form: Thu 2021-07-01 00:00:00 PST\n (in UTC): Wed 2021-06-30 16:00:00 UTC\n UNIX seconds: @1625068800\n From now: 10 months 21 days ago\n..............\n\nCalendar example:\n..............\n Original form: *-1/4-5 0/2:00:00\nNormalized form: *-01/4-05 00/2:00:00\n Next elapse: Mon 2022-09-05 00:00:00 PST\n (in UTC): Sun 2022-09-04 16:00:00 UTC\n From now: 3 months 13 days left\n..............\n\n"}]}]},"backlinks":[{"path":"/linux.systemd","title":"systemd"},{"path":"/linux.systemd.transient-units","title":"systemd transient units"}]},"__N_SSG":true} |