51

I have a timer/service unit-set that should run once a day under --user conditions. It shows up with systemctl --user status and gets logged in journal but there is a part of the command that fails.

It seems that something in the command is not being interpreted correctly. I want to futz with the unit file and run the service, examine the log, etc to debug the issue; however editing the timer to trigger a minute in the future, waiting, and checking the log is... tedious.

Can do something like systemctl --user execute xxxxxx.service to just run the dang thing as if the timer triggered?

1 Answer 1

34

You can activate any unit manually, unless it contains a RefuseManualStart=yes and/or RefuseManualStop=yes directive (which do exactly what they say). Just issue systemctl --user start <whatever> (and systemctl --user stop <whatever> to do the opposite).

To quote systemctl(1):

start PATTERN...

Start (activate) one or more units specified on the command line.

<...>

stop PATTERN...

Stop (deactivate) one or more units specified on the command line.


Note that manually starting the timer's paired unit does not affect the timer's own state (i. e. it won't change the timer's LastTrigger* or NextElapse* properties) and does not change the time it will next elapse. Forcibly elapsing a timer is not supported in systemd.

7
  • Not working here: Failed to restart {foo}.service: Operation refused, unit {foo}.service may be requested by dependency only.
    – eMPee584
    Jul 9, 2019 at 18:01
  • 1
    @eMPee584 Since this answer was written, systemd gained new directives RefuseManualStart= and RefuseManualStop= (which do exactly what they say). I've updated my answer to mention that.
    – intelfx
    Jul 29, 2019 at 3:13
  • 1
    I tried this on the fstrim.timer. But for the timer it doesn't do anything. (enables it I think) When issued on fstrim.service, probably something happened. Is there no way to trigger the timer so it shows it was actually executed?
    – JPT
    Apr 10, 2020 at 12:13
  • 16
    @JPT "starting" a timer means that the timer starts ticking. Forcibly elapsing a timer is not supported in systemd. If you need this, just start the paired unit directly (in your case, fstrim.service).
    – intelfx
    Apr 12, 2020 at 3:58
  • 2
    So no, there is no way to manually trigger a timer. You may want to work that information into the answer, since it's what is actually answering the question.
    – miken32
    Jan 17, 2023 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .