TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Working with Systemd Timers

80 点作者 skwee3572 个月前

11 条评论

tombert大约 2 个月前
I know everyone hates on systemd, but I&#x27;ve generally been happy with it, in no small part because I find the timers to be pretty sensible.<p>They are, in all ways that I care about, simply better than cron, and especially in NixOS they&#x27;re really easy to set up.
评论 #43359341 未加载
评论 #43359173 未加载
评论 #43359622 未加载
评论 #43359706 未加载
评论 #43372505 未加载
timrichard大约 2 个月前
When I started using systemd timers, I really liked the systemd-analyze calendar facility, to calculate n trigger times for a given calendar expression.<p>For example, show the next five trigger times for the end of the last day when the month has 31 days :<p>systemd-analyze calendar --iterations=5 &#x27;*-*-31 23:59:59&#x27;
notepad0x90大约 2 个月前
There is one huge advantage of cron that is usually missed with such comparisons. cron is dead-easy to create and maintain. Systemd timers make sense in certain situations, but in 90%+ of my use cases so far, the added complexity really adds up the amount of time I&#x27;m administering my systems. I&#x27;ve been in a situation where I needed to troubleshoot why a systemd timer wasn&#x27;t triggering, and I didn&#x27;t like that experience at all. To me, it is something I would use if I actually needed it, it isn&#x27;t a 1-to-1 replacement for cron.
评论 #43359339 未加载
评论 #43371618 未加载
评论 #43363098 未加载
评论 #43359363 未加载
merpkz大约 2 个月前
Minor nitpick - shouldn&#x27;t you first define the service and only then a timer for it? Otherwise since you enabled timer and are still trying to figure out how to write service, systemd won&#x27;t have anything to run when timer triggers. Maybe I am wrong, but that just feels like logical order. Anyways, after years on hating on systemd I also started to embrace it and porting my cron jobs to systemd timers and I must admit it&#x27;s really nice, the overall overview with list-timers, next execution timestamp, total execution time, ordering of services so one can run after another is completed and of course the logging in journal so I can filter output and keep track of everything it&#x27;s just wonderful experience.<p>EDIT: yea, the email reporting is certainly missing, but it was hard to control it since whole STDOUT was shipped, which is not what I wanted most of the time anyways. It would be good to come up with some way to still have small overview emails sent about important jobs done, maybe a dependency service which starts when important job finished and just sends an email about that
kinglawrence大约 2 个月前
Really liked this read. Is anyone able to explain how the backup.timer runs the backup.service? It wasn&#x27;t obvious to me where the trigger was defined. I guess it&#x27;s just inherent to what that unit type does, and the fact that both units are named backup? What is the name for that &quot;package&quot; of units that make up the whole backup program?
评论 #43359510 未加载
MantisShrimp90大约 2 个月前
It took a minute to setup, but using a combination of rsync and timers to backup system files has done wonders to decrease my anxiety around upgrades on arch
评论 #43358996 未加载
akeck大约 2 个月前
I used systemd user timers, a shell script, and an HDHomerun to make a simple VCR.
bhaney大约 2 个月前
I like systemd&#x27;s timers when they&#x27;re appropriate, but I really think the author&#x27;s use case here is better suited to cron. The &quot;issues&quot; he listed for cron aren&#x27;t very good either.<p>&gt; If you want to execute pre&#x2F;post commands you have to do it inside the script itself<p>So?<p>&gt; There are no built-in logs<p>Every cron implementation I can remember using logs each run to syslog <i>and</i> emails me the output of the run by default<p>&gt; There is no built-in status monitoring<p>I can&#x27;t think of any built-in status monitoring that systemd has for timers that&#x27;s materially different from cron&#x27;s logging&#x2F;emailing<p>&gt; If the system is down when the cron needs to run, the cron will be missed<p>Some cron implementations support this and some don&#x27;t. Most modern ones that I&#x27;m aware of do.<p>Much more significantly, the amount of setup involved in a systemd timer is way higher than putting a line in a crontab, especially for the author&#x27;s case of just running a backup script.<p>Cron only involves running `crontab -e` and adding the line &quot;@daily &#x2F;path&#x2F;to&#x2F;script.sh&quot; (which also handles the author&#x27;s issue of cron &quot;skipping&quot; runs if the system was powered off, assuming the cron implementation uses something modern like anacron)<p>Systemd involves writing a 7 line timer unit file, an additional 5 line service file, running a daemon-reload, then enabling the timer. It turns what&#x27;s usually a 10 second mindless task into a much more involved procedure. That can be worth it if there are material benefits from it, but I&#x27;m not really seeing them here.
评论 #43359393 未加载
评论 #43359400 未加载
评论 #43359252 未加载
评论 #43359224 未加载
rs_rs_rs_rs_rs大约 2 个月前
I use them all the time, my only wish is they get rid of the .service file and make it possible to define the service inside the .timer file.
评论 #43365812 未加载
评论 #43367952 未加载
dmd大约 2 个月前
I would love to see something like <a href="https:&#x2F;&#x2F;github.com&#x2F;isd-project&#x2F;isd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;isd-project&#x2F;isd</a> but for systemd timers.
burnJS大约 2 个月前
This is cool and after learning of this I&#x27;m tempted to convert my crons. I currently use systemd for running a redis queue and it&#x27;s worked great for years.