Talk:Systemd/Timers

From ArchWiki

Service File Example

It would be nice to add an example service unit file alongside the timer unit example. While there are examples of service units in the main systemd article, the service unit that accompanies a timer might be different. For example, wouldn't it usually be a good idea for a service controlled by a timer to have Type=oneshot?

Xordspar0 (talk) 22:25, 23 March 2016 (UTC)Reply

If your concern is that a timer might try to start a service while it is already running, the service type won't help with that. oneshot only prevents dependent units from starting before the service exits, but timers are not dependent. Also consider a service that runs forever: such a service can still be reasonably started by a timer, using OnBootSec for example. Silverhammermba (talk) 19:33, 24 March 2016 (UTC)Reply
One might look at system timers for service file examples.
% systemctl list-timers
pick some service file, say shadow.service, and
% systemctl cat shadow.service
The .timer file can also be seen in a similar manner. Since shadow is part of base group, it will be installed on virtually any system.
Regid (talk) 19:50, 25 April 2019 (UTC)Reply

oneshot service and OnUnitActiveSec vs. OnUnitInactiveSec

This page contains an example of configuring a type=oneshot service to run with regular intervals with a monotonic timer. The relaunch timeout is defined by OnUnitActiveSec in the [Timer]-section.

I just started to encounter mysterious errors, with the timer running once in boot and then going in inactive state, after upgrading to a newer version (it was Debian 10, but I suspect the same problem applies to Arch Linux)

In this discussion, Lennart Poettering says that the combination of type=oneshot and OnUnitActiveSec=xxx does not make sense. If the service finishes before it has been active (running?) the given time, the relaunch may fail.

https://github.com/systemd/systemd/issues/6680

So I wonder, if OnUnitInactiveSec would be the correct parameter to start counting relaunch after the service has finished.

—This unsigned comment is by Juhanima (talk) 14:52, 15 October 2019‎. Please sign your posts with ~~~~!


Oneshot service and RemainAfterExit

I noticed the timer would not attempt to start the `oneshot` service again if `RemainAfterExit` was used.

This combination was resulting in timer being stuck in `Left == N/A` state after first trigger:

   cat >/etc/systemd/system/my_script.timer<<EOF
   [Unit]
   Description=schedule regular restarts of my script
   
   [Timer]
   OnCalendar=*-*-* 03:00:00
   
   [Install]
   WantedBy=multi-user.target
   EOF
   cat >/etc/systemd/system/my_script.service<<EOF
   [Unit]
   Description=my script
   After=syslog.target network-online.target
   
   [Service]
   Type=oneshot
   RemainAfterExit=yes
   
   ExecStart=/usr/bin/bash /path/to/my_script.sh
   
   ProtectSystem=true
   
   RestartSec=60s
   TimeoutSec=120s
   
   [Install]
   WantedBy=multi-user.target
   EOF

As soon as I removed `RemainAfterExit` timer seems to be working as expected. I might be incorrect to say this but I think this is the feature of systemd - it will not attempt to start the service which is in "active" state.

Gregosky (talk) 06:05, 26 March 2020 (UTC)Reply

Missing "systemctl restart" command after editing an already enabled timer

Trying to run clamav-freshclam-once.timer more often then once a day, a was trying to see the NEXT timer run time with systemctl list-timers. Even after systemctl daemon-reload the NEXT column stayed "blank" with only a minus (-) sign. Finally I figured the not-picked-up-timer-changed out that the trick is to run systemctl restart clamav-freshclam-once.timer. Which section on the "Systemd/Timers" wiki page would fit an edit example? Management? Examples? Other...? Probackup-nl (talk) 14:55, 7 February 2024 (UTC)Reply