Top
Best
New

Posted by yacin 8 hours ago

Love systemd timers(blog.tjll.net)
227 points | 152 commentspage 2
frays 4 hours ago|
I've been using Linux for over 20 years, systemd for over 10.

Yet there's always something new to learn and actually consider as another useful tool.

egorfine 2 hours ago|
I'm using Linux for about 30 years and apparently we were all wrong using cron for decades.
sammy2255 4 hours ago||
I've converted all my crons to systemd timers+services over the past year but cant help but think it's sort of.. less tangible than cron

Like imagine trying to explain systemd timers and services and unit files to a beginner.

darkwater 3 hours ago||
> Like imagine trying to explain systemd timers and services and unit files to a beginner.

I think it's... easier? Like "systemd is the place where your system manages all the processes it needs to run. Part of those processes can be run on a schedule, or on a timer, and you define them using this simple text file".

PunchyHamster 1 hour ago||
cron is easier for easy stuff ("just run this every 10 minutes") but harder for hard stuff ("run it every 8 hours but with randomized offset so not all machines at once do it, but also if machine was down when it should run, run it immediately").

It is also easier to debug as every job gets its own log rather than trying to write to system mailer nobody had set up with the job errors

mindcrime 3 hours ago||
I haven't always been the biggest fan of systemd in some regards, but I will say that I mostly agree with this sentiment. I've almost completely quit using cron, and now favor systemd timers for scheduled jobs - at the "system" level anyway. I might still embed Quartz for scheduling that's scoped to a particular application or something.

Why? It's one of those fuzzy and somewhat hard to explain things. The systemd approach just maps more cleanly to my mental model of "how things should work" I guess. And maybe some of it is that I did indeed experience plenty of " Ambiguous $PATH settings make cron script execution difficult to predict" in the past, although it's not just that.

I won't sit here and claim that systemd timers are necessarily better than cron in any universal / objective sense. But they've won me over, for what it's worth.

lanycrost 4 hours ago||
systemd is complex on first view, but after using it you didn't want to use anything else. It's handy to manage everything using systemctl
alyandon 4 hours ago||
That and systemd having actually useful man pages.
the_real_cher 4 hours ago|||
This is such a modern view. People used to HATE systemd when it first came out, but I always liked it and knew people would eventually come around and its nice to see they finally did!
weaksauce 2 minutes ago|||
the thing for me is I started using the init system and while it was fine it always felt brittle for some reason. systemd feels solid and robust like it was well thought out. maybe i'm off base and didn't know how to use init effectively but it was my feeling.

that and cron always felt fragile too with a lot of quirks and limitations you had to work around instead of being a robust thing from the start.

egorfine 2 hours ago|||
Some people are stubborn and refuse to see how obviously superior systemd is to the old ways. Me included.
egorfine 2 hours ago|||
Some people see it differently. As in: after using it they don't want to use it. I hate systemd with passion.

But that's because I'm old because obviously systemd-* is the only right way and everyone else who see things differently is a pundit.

bjoli 2 hours ago||
I hard disagree. Previously I could use what I knew about Linux commands to read logs and administer the systemm. Systemctl knowledge does not generalize.

I have done scheme all my life, which is why I prefer shepherd. Not only is it in a syntax that i can use elsewhere, I get completion in Emacs.

egorfine 2 hours ago||
We have used cron perfectly fine for decades and it served us well within its very clear limitations.

But now obviously we were so blind and wrong all this time and the only true solution is of course systemd.

bigbuppo 2 hours ago||
Thank Lennart you degenerate apostates are finally starting to see the light of His glorious creation. Hallowed be thy systemd-journald.
tim-projects 50 minutes ago|||
After reading this article I'm convinced that what we need is systemd timers fronted by a vibe coded crontab -e emulator.

Coz it's looks crazy complicated to set them up.

bakugo 2 hours ago|||
Has it actually served you well? Because it hasn't served me well at all.

I am not the biggest fan of systemd, but today I will always reach for a systemd timer over cron simply due to the sheer amount of bad experiences I've had with cron. Hours upon hours wasted trying to troubleshoot crons that weren't working due to some stupid obscure issue, having to use dirty hacks to monitor for success or retry failed jobs.

A few years ago I was trying to run a very simple bash script with cron and the script just died halfway through for no reason. Nothing in logs, worked fine when run directly, but in cron it just stopped halfway through a loop. Never figured out the cause, just gave up and used a timer instead, which worked fine. Never touched cron again after that.

The ease and convenience of monitoring and troubleshooting alone are worth switching over.

egorfine 2 hours ago||
Let me state once again: "within its very clear limitations".

Once you learn that env in cron is not same as in your shell and once you learn to redirect output to loggers - it works just fine.

It would be a lie to say that I never debugged cron and sure it's annoying.

> and the script just died halfway through for no reason

Unrelated to cron. Bad script.

erxam 1 hour ago|||
Systemd will reign supreme for a millennium if the answer to every question or complaint about non-systemd tools is "you're holding it wrong".
dogleash 1 hour ago||
As a user I'm kinda whatever about the tools because the answer to my complaints about systemd is also "you're holding it wrong."
dijit 1 hour ago||||
I'm sympathetic, but "bad script" is an awful assertion.

We are all guilty of making bad scripts, bash is a disgusting degenerate language (and I love it). The way we learn to write good scripts is by writing bad scripts in enough amounts to get bitten by all the warts.

One thing I really love about cron, is that if you set up mail on the server (which: you should btw), then cron actually sends emails if it sees anything in stdout and stderr.

I am a dyed in the wool systemd non-believer, but I really do like the timers.

bakugo 1 hour ago||||
I don't agree that these are just limitations. The fundamental problem cron tries to solve is very simple: I want to run a program automatically at specific times. There are probably many features of systemd timers that can be considered niche or extraneous in solving this problem, but the ability to easily know when the program last ran and what its exit code and stderr output were is not one of them. I believe that if an alleged solution to this problem doesn't provide at least this, it's not really solving the problem.

> Unrelated to cron. Bad script

Again, worked fine when run manually, worked fine in a systemd timer. Pretty sure I still have it running today and it continues to work fine without ever failing.

izacus 1 hour ago|||
So basically it took you decades to learn all the bugs, UX issues and problematic quirks and now you're complaning someone built something better? :)
mschuster91 1 hour ago||
> But now obviously we were so blind and wrong all this time and the only true solution is of course systemd.

Come on, dude. That's unnecessarily polemic.

cron et al have served us for decades, yes. But that doesn't mean that cron is the solution that needs to accompany us until the heat death of the universe or year 2038, whatever comes first.

I agree, the systemd folks haven't exactly been the best when it comes to PR or when it comes to being even near feature parity with what they tried to replace. But now, they aren't just at feature parity, they surpassed plain old cron.

Maybe it is time to lay cron to rest, at least slowly.

egorfine 3 minutes ago||
> that doesn't mean that cron is the solution that needs to accompany us until the heat

Yeah I agree.

> systemd folks haven't exactly been the best when it comes to PR

It's deeper than that. Systemd folks are enemies of Linux. First, it's "fuck your opinion, do as we say" attitude which makes me want to throw away everything that comes from that poisonous well. Second, it's the embrace and extinguish strategy employed by the systemd project. And third, systemd author is up to no good: https://news.ycombinator.com/item?id=46784572

progforlyfe 2 hours ago||
This is a very good intro to systemd timers -- I think you convinced me to finally start using them. Love the "list-timers" thing as well. With cron, it never seemed easy to me to get a picture of all the cron jobs running on a box. I'd need to check crontab for all users, as well as /etc/cron.d/, as well as the daily/hourly/monthly directories.

And in fact I do have a use-case for needing to run something ~5 minutes after the system boots and then every ~12 hours onward from there. It's great that systemd timers has me covered!

ktm5j 5 hours ago||
Oh I love them quite a lot! I use them to run all of our backup jobs, easy to set up and have never had an issue.
pjot 2 hours ago||
After years of using orchestration tools like airflow and dagster so many lightbulbs have just lit up in my head.

I wish documentation for tools would explain their abstractions concepts in terms of its primitives.

Great post, thanks!

jjgreen 8 hours ago||
I've been almost convinced by systemd (and have switched to using it), but God the syntax of those service files is so ugly ...
zamadatix 5 hours ago||
Never thought I'd see hackers saying INI format looked ugly of all things. It's basic, sure, but that's a good thing for something meant to be easily editable by hand from any editor. Otherwise, it's just key value pairs in named sections, how ugly can it be about that?
jjgreen 5 hours ago||||
key-value pairs where the = cannot be surrounded by spaces, so I have to write

  [Service]
  Type=oneshot
  WorkingDirectory={{ home }}/current/
  Environment=RAILS_ENV=production
  ExecStart=/bin/sh -lc "bin/db-backup --verbose"
which fills me with sadness
voxic11 5 hours ago|||
Whitespace immediately before or after the equals sign is completely ignored by the parser. Its the standard INI format.
yjftsjthsd-h 5 hours ago|||
What? You absolutely can have spaces; most of mine look more like

  [Service]
  Type             = oneshot
  WorkingDirectory = %h/current/
  Environment      = RAILS_ENV=production
  ExecStart        = /bin/sh -lc "bin/db-backup --verbose"
jjgreen 5 hours ago||
Friend, you have changed my life
weavie 4 hours ago|||
Is this one of those cases where at one point you had an error in the file and you figured it was down to spaces? You fixed that issue, it still didn't work but from that point you never thought to question the assumption.

I find myself doing this sort of thing all the time..

jjgreen 1 hour ago|||
Somewhere in my head I had that spaces caused a syntax error, and the UI for systemd is not obvious when you first start using it ... so if it's working then leave well alone. I'll be making all of my .service files (not so many) human-readable in the near future!
troyvit 3 hours ago|||
That was (cough still is) ddclient for me.
bblb 1 hour ago|||
My epiphany a month ago was that I can use

   Environment = MULTIPLE=environment VARIABLES="in single line"
ramon156 5 hours ago|||
TOML would look a lot more quiet, but I'm not sure if TOML would be a good fit
kevinmgranger 4 hours ago||
unit files barely have any nesting, so the INI-like format is already 90% of the way towards TOML, no?
mrweasel 5 hours ago|||
There's definitely some weirdness to certain parts of systemd service files, but was a huge improvement over Upstart and the old SysV-style init scripts.

Over all I think Systemd get way to much criticism. You don't have to use all the parts, but if you care to go through the documentation you'll find interesting features such as journald log-shipping and systemd-machined which can manage containers and VMs.

egorfine 2 hours ago|||
As a passionate systemd hater I would say I do not agree. Cron syntax is worse.
SEJeff 5 hours ago|||
Oh yes, because the well documented clean syntax of sys v init shell scripts was so nice.

If I never recall hacking in ulimit calls in the top of buggy shell scripts for crappy old services that done respect pam_limits it won’t be soon enough.

linsomniac 4 hours ago|||
Hard disagree. Compared to an init script, with all its boilerplate, I'd take a systemd unit file.
WesolyKubeczek 6 hours ago|||
Could have been worse.

Could have been YAML.

Could have been XML.

silvestrov 6 hours ago|||
XML would have the advantage of having a grammar so we could validate the config files.

It would also make it much simpler to make good GUI editors for the files instead of the Notepad approach most unix config files take.

pwdisswordfishq 5 hours ago|||
The systemd dialect of INI is actually pretty well-defined though.

https://www.freedesktop.org/software/systemd/man/latest/syst...

WesolyKubeczek 5 hours ago||||
Since systemd is successfully parsing its INI files, and barks at you when you put weird shit into them, a grammar for them does exist as well.

XML is that wonderful format that gave us vulnerabilities like death by million laughs, up to a certain moment, you could MitM DTDs, and a whole slew of everything-XML stuff back when XML was like AI is today, none of which I miss today.

Oh, and remember times when programmers would argue whether argument order in XML files should be significant or not?

But XML books with their idealized XML future description did give me the same warm fuzzies as some intricate clockwork mechanism to a Victorian geek.

Juliate 5 hours ago|||
There are good GUI editors for XML?
jjgreen 5 hours ago||||
To be honest, I think either of those would have been better ...
WesolyKubeczek 5 hours ago||
/me cowers in fear
Tsiklon 3 hours ago||||
XML - I see you’ve used macOS’ LaunchD, the system that inspired Systemd
WesolyKubeczek 1 hour ago||
Yeah, I'm a man of culture like this. However, systemd with its service dependencies runs circles around launchd in pretty much every aspect.
wpm 4 hours ago|||
Could have been better.

Could have been XML Property Lists.

ducks

whateveracct 5 hours ago||
This is why I like NixOS. Defining systemd services in it is very neat.
louiskottmann 1 hour ago|
And you immediately lose the ability to do `crontab -l` on any server to know its scheduled tasks.

Now you get to look around the myriad of places where you can put systemd files, and figure out which ones are base services and which ones are custom, with no general convention to go about it. Nope.

TazeTSchnitzel 1 hour ago||
If you had read the article, you would have seen its answer to this.
arter45 1 hour ago||
systemd list-timers

With —-all

More comments...