14

I'm trying to setup a systemd timer to run twice a day during a working week. Once is at 7:00 AM, and once at 1:00 PM. The *.timer and *.service files are below.

I install and enable them, and everything is OK:

cp callboot-update.service /etc/systemd/system
cp callboot-update.timer /etc/systemd/system

if ! systemctl enable callboot-update.service; then
    echo "Failed to enable callboot-update.service"
    exit 1
fi

if ! systemctl enable callboot-update.timer; then
    echo "Failed to enable callboot-update.timer"
    exit 1
fi

And reload the daemon. Again everything is OK:

if ! systemctl daemon-reload; then
    echo "Failed to daemon-reload"
fi

if ! systemctl reset-failed; then
    echo "Failed to reset-failed"
fi

However, checking the status shows the timer is in n/a status, and not scheduled to run:

$ systemctl list-timers --all

NEXT                         LEFT        LAST                         PASSED        UNIT                         ACTIVATES
Wed 2019-12-25 03:02:08 EST  6h left     Tue 2019-12-24 03:02:05 EST  17h ago       system-update.timer          system-update.service
Wed 2019-12-25 04:02:07 EST  7h left     Tue 2019-12-24 04:09:05 EST  16h ago       auto-update.timer            auto-update.service
Wed 2019-12-25 06:46:46 EST  9h left     Tue 2019-12-24 06:39:05 EST  14h ago       apt-daily-upgrade.timer      apt-daily-upgrade.service
Wed 2019-12-25 06:50:27 EST  9h left     Tue 2019-12-24 18:30:05 EST  2h 23min ago  apt-daily.timer              apt-daily.service
Wed 2019-12-25 10:55:43 EST  14h left    Tue 2019-12-24 13:22:24 EST  7h ago        motd-news.timer              motd-news.service
Wed 2019-12-25 16:46:06 EST  19h left    Tue 2019-12-24 16:46:06 EST  4h 7min ago   systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2019-12-30 00:00:00 EST  5 days left Mon 2019-12-23 00:00:11 EST  1 day 20h ago fstrim.timer                 fstrim.service
n/a                          n/a         n/a                          n/a           callboot-update.timer        callboot-update.service

How do I get the timer out of n/a status so its starts running as intended?


$ ls -Al /etc/systemd/system/callboot-*
-rw-r--r-- 1 root root 234 Dec 24 20:38 /etc/systemd/system/callboot-update.service
-rw-r--r-- 1 root root 222 Dec 24 20:38 /etc/systemd/system/callboot-update.timer
$ cat callboot-update.timer
[Unit]
Description=Run Callboot update.service

[Timer]
OnCalendar=Mon..Fri *-*-* 07:00:00
OnCalendar=Mon..Fri *-*-* 13:00:00
RandomizedDelaySec=3000
Persistent=true

[Install]
WantedBy=timers.target
$ cat callboot-update.service
[Unit]
Description=Update Callboot without user prompts

[Service]
Type=oneshot
ExecStart=/usr/sbin/callboot-update

[Install]
WantedBy=multi-user.target
jww
  • 11,918
  • 44
  • 119
  • 208

2 Answers2

13

You must start the .timer unit in order to schedule it – just like you must start .service units in order to make the associated daemon run. Your post shows neither systemctl start, nor systemctl enable --now, nor any other commands which would queue a start job.

systemctl daemon-reload will not automatically start any newly added dependencies for units which are already running (such as timers.target in this case) – the symlink that 'systemctl enable' created will only really take effect on next boot, or if you somehow manually restart timers.target.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
2

I've had this problem and I noticed that the corresponding service was hanging and its status was activating (start). For this reason it was not triggered.

I stopped the service and then the timer showed the next trigger time as expected. Perhaps some people saying that a reboot helped them actually had the same problem.

Lev Levitsky
  • 410
  • 1
  • 5
  • 17