2

So I have my service unit (runs some node code) and my timer unit Service:

[Unit]
Description=foo

[Service]
Type=oneshot
ExecStart=/home/ubuntu/services/foo/start.sh

Timer

[Unit]
Description=foo timer 

[Timer]
OnBootSec=0min
OnCalendar=*-*-* 05:01:00 UTC 
Unit=foo.service 

[Install]
WantedBy=multi-user.target

I understand that systemctl start foo.timer , will start the timer unit but not the service unit immediately (without reboot) and systemctl enable foo.timer will not start the timer unit but start it when the system boots up.

I wanted to start the timer immediatey so I used the former. It did start the timer but it also started my foo.service as I started the timer even though the OnCalendar conditions were not met. It still started correctly at the OnCalendar time, too (I was testing so I chose a time in the near future).

I'm wondering if there is anything in my unit file causing this. I thought that starting the timer would not start the service but only start the service when the condition is fulfilled in the timer.

I did also test the system enable way and that one actually did behave correctly. I enabled my foo.timer. Reboot the system. Timer was active and service wasn't immediately. When the OnCondition time came, the service ran.

3

From systemd.timer(5):

If a timer configured with OnBootSec= or OnStartupSec= is already in the past when the timer unit is activated, it will immediately elapse and the configured unit is started. This is not the case for timers defined in the other directives.

Since your timer unit sets OnBootSec=0min, it will always start the service unit immediately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.