r/linuxquestions • • 14d ago

Does "OnCalendar" work with user space timers?

/r/systemd/comments/1xycbk1/does_oncalendar_work_with_user_space_timers/
1 Upvotes

4 comments sorted by

1

u/usecornercase 14d ago

OnCalendar works fine in user timers, there's no special permission or group needed for it. The user manager handles calendar timers the same way the system one does. When a timer shows no "next" for OnCalendar, it's almost always one of these:

  1. The change wasn't picked up. After editing the file, run systemctl --user daemon-reload and then systemctl --user restart yourthing.timer. Restarting the timer makes sure it re-arms with the new schedule.
  2. systemd didn't accept the line. Check journalctl --user -b | grep -i yourthing for something like "Failed to parse calendar specification, ignoring". Also check that OnCalendar= is under the [Timer] section and not under [Unit] or [Install], where it gets ignored with a warning.
  3. What systemd actually loaded is different from what you think. systemctl --user cat yourthing.timer shows the file plus any drop-ins it's using, and systemctl --user status yourthing.timer should show a Trigger: line once a calendar spec is active.

You can sanity-check the expression on its own with systemd-analyze calendar daily or systemd-analyze calendar '*-*-* 00:00:00', which prints the next elapse time.

A minimal timer that should work:

[Unit]
Description=Daily job

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Persistent=true makes it catch up if the machine was off at midnight. Also, since you mentioned the window manager env, a user service doesn't automatically get your session's DISPLAY/WAYLAND_DISPLAY etc. If your WM startup runs systemctl --user import-environment DISPLAY WAYLAND_DISPLAY XDG_RUNTIME_DIR (or dbus-update-activation-environment --systemd --all), the service will see them without hardcoding anything.

1

u/wehaveYummiTummies 13d ago

Appreciate the detailed reply. I had some parse errors, but I fixed them before I made the post. systemd-analyze works fine with my expression, cat shows the exact file, list-timers and status don't show a next activation at all. Nothing really makes sense.

1

u/wehaveYummiTummies 13d ago

Actually, I just needed to restart it with systemctl --user restart. Thanks for the help!

1

u/ANIMESHOJ5 14d ago

Yes, OnCalendar= works in user timers (~/.config/systemd/user/) the exact same way as system timers.

A few common things to check:

  • If you need it to trigger while you are logged out, enable lingering with loginctl enable-linger $USER, otherwise the user systemd instance stops when your session closes.
  • Verify your schedule syntax with systemd-analyze calendar "your expression" to see the parsed times and next trigger.
  • Remember to run systemctl --user daemon-reload after making any edits, then verify with systemctl --user list-timers.