Progrider

Programming discussion

Board index
General · Open discussion · cron systemd

systemd timers are cron with extra steps. fight me

Every six months somebody tells me to move my jobs to timers. So: two files instead of one line, and a unit name I now have to think of, so that I can read the output through journalctl instead of a plain file.

What exactly do I get? I've been running the same crontab since before some of you could type.

16 replies

I had the same view until a sensor box was off for a night and missed its backup. Persistent=true runs the missed job at next boot. With cron you need anacron for that.

The other one for me is overlap. A timer won't start the service again while it's still running. With cron a slow job stacks up unless you remember to wrap it in flock.

flock -n /tmp/x.lock cmd. Eleven characters plus a filename.

And you remember it every time? Honest question.

No. I found out about flock when four rsyncs were running at once.

Timers still need a service file, a timer file and a daemon-reload to do what one line did. I'm with sysv. Grudgingly, since I don't agree with him about anything else.

For the record here's what the whole thing actually is:

# backup.service [Service] Type=oneshot ExecStart=/usr/local/bin/backup.sh

# backup.timer [Timer] OnCalendar=*-*-* 02:15:00 Persistent=true RandomizedDelaySec=300 [Install] WantedBy=timers.target

systemctl enable --now backup.timer, and systemctl list-timers tells you when it last ran and when it runs next. Crontab can't tell you the last one.

Cron's environment has caught me more than anything else on this list. PATH with nothing in it, wrong cwd. A service unit can have the same issue but at least you can test it with systemctl start and get the same environment as the real run.

user timers need loginctl enable-linger or they stop when you log out. that one cost me a week of missing backups

Fine. One real point: cron mails me on failure and it's built in. What do you do with a timer?

OnFailure= pointing to a unit that sends a mail. You have to write that unit. I'll give you that one, cron wins on this.

I'll take it. Thread closed, I win.

On points perhaps. My timers are still running.

Reviving to say I moved one of my boxes to timers after this thread and then moved it back when I realised I'd forgotten how to read the journal on a read-only rescue boot. journalctl -D /mnt/var/log/journal for next time.

Add a reply

Formatting help. Public, and removed when the thread expires.

Type name#secret for a tripcode, an identity others can't copy.

Posts and requests are logged for research. Privacy notice.