4

I have the following systemd myscript.service unit that executes an script:

[Unit]
Description=MyScript
Wants=time-sync.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/local/bin/test.sh -a
ExecStop=/usr/local/bin/test.sh -b

[Install]
WantedBy=multi-user.target

And I want to restart it each minute with the following Systemd myscript.timer unit:

[Unit]
Description=Schedule script execution

[Timer]
OnCalendar=*:0/1

[Install]
WantedBy=timers.target

It only works the first time, after it, the status remains in n/a:

# systemctl list-timers
NEXT                         LEFT        LAST                         PASSED      UNIT                         ACTIVATES
n/a                          n/a         Tue 2019-10-15 14:50:01 EDT  3ms ago     myscript.timer               myscript.service

~

1 Answer 1

5

If a .service unit will be executed from a .timer unit, it can't have RemainAfterExit=true. The systemd documentation mentions that:

Note that in case the unit to activate is already active at the time the timer elapses it is not restarted, but simply left running. There is no concept of spawning new service instances in this case. Due to this, services with RemainAfterExit= set (which stay around continuously even after the service's main process exited) are usually not suitable for activation via repetitive timers, as they will only be activated once, and then stay around forever.

So, remove RemainAfterExit=true and it will work.

1
  • BTW: You should be able to say OnCalendar=minutely, which is a bit clearer. Also you might want to mention AccuracySec (though the default one minute should be fine here).
    – derobert
    Oct 15, 2019 at 19:19

You must log in to answer this question.

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