1

I have a nodejs gui program (does not requires user interaction), which needs to be run at every 40th minutes at each hour. Say run at 05:40PM, 06:40PM, 07:40PM and so on. In a Debian server, I have enabled a systemd timer using:

systemctl --user enable my_program.timer

Problem is, scheduling starts at the given time and finishes successfully. But immediately after that program starts again and finishes successfully.

Say program started at 5:40PM and finished at 5:45PM. After a minute or so, say at 5:46PM program starts again and finishes. Then this happens again at next time, so at 6:40PM.

This happens every time every hour. Also, if I reboot the server, after logging into that user account, program starts immediately instead of waiting 5 minute.

  1. How to stop auto running second time?
  2. How to force to start 5 minutes after reboot?

Content of /home/user/schedule.sh

#! /usr/bin/bash
cd /home/user/my_program && DISPLAY=:0 /usr/bin/node ./index.js

Content of /home/user/.config/systemd/user/my_program.service

[Unit]
Description=My Program

[Service]
ExecStart=/home/user/schedule.sh

Content of /home/user/.config/systemd/user/my_program.timer

[Unit]
Description=My Program Timer
Requires=my_program.service

[Timer]
Unit=my_program.service
OnCalendar=*-*-* *:40:*
OnBootSec=5 minutes

[Install]
WantedBy=timers.target
4
  • 1
    OneBootSec should be OnBootSec. Commented Dec 15, 2020 at 0:50
  • @ajgringo619 Thanks, changed it. But still after reboot, starts immediately.
    – drmirk
    Commented Dec 15, 2020 at 7:31
  • Try OnBootSec=5min. Commented Dec 15, 2020 at 20:28
  • @ajgringo619 no change, still starts immediately
    – drmirk
    Commented Dec 16, 2020 at 8:29

1 Answer 1

0

Let's focus on one question here: the duplicate runs each hour. You've used this syntax for it:

OnCalendar=*-*-* *:40:*

According to man systemd.time, the wildcard in the seconds place means it matches every second of the 40th minute of every hour. You can confirm this with the included systemd-analyze tool, which has a calendar sub-command:

systemd-analyze calendar --iterations=5 "*-*-* *:40:*"
Normalized form: *-*-* *:40:*
    Next elapse: Thu 2020-12-17 17:40:00 EST
       (in UTC): Thu 2020-12-17 22:40:00 UTC
       From now: 15min left
       Iter. #2: Thu 2020-12-17 17:40:01 EST
       (in UTC): Thu 2020-12-17 22:40:01 UTC
       From now: 15min left
       Iter. #3: Thu 2020-12-17 17:40:02 EST
       (in UTC): Thu 2020-12-17 22:40:02 UTC
       From now: 15min left
       Iter. #4: Thu 2020-12-17 17:40:03 EST
       (in UTC): Thu 2020-12-17 22:40:03 UTC
       From now: 15min left
       Iter. #5: Thu 2020-12-17 17:40:04 EST
       (in UTC): Thu 2020-12-17 22:40:04 UTC
       From now: 15min left

So that's a problem.

The second problem is that you have included Requires= in your timer. In man systed.unit, the documentation for the Requires= directive says this:

If this unit gets activated, the units listed [In Requires=] will be activated as well.

So that could also cause the target service to be loaded a second time as well.

Open a new question about OnBootSec= timing-- that's a separate issue.

1
  • Using OnCalendar=*-*-* *:40:00 and removed Requires= from timer. And it solved both problems.
    – drmirk
    Commented Dec 18, 2020 at 13:59

You must log in to answer this question.

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