msantos / runcron

simple, safe, container-friendly cron alternative

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runcron exited after first success task run

ttys3 opened this issue · comments

commented

this is not work as expected like crond:

the job should runs at every minute, not once and exted

❯ ./runcron  -v '*/1 * * * *' bash -c 'echo $(date)'
now[1585568711]=Mon Mar 30 19:45:11 2020
next[1585568760]=Mon Mar 30 19:46:00 2020
now[1585568760]=Mon Mar 30 19:46:00 2020
next[1585568820]=Mon Mar 30 19:47:00 2020
last exit status was 0, sleep interval is 49s, command timeout is 60s
running command: timeout is set to 60s
Mon 30 Mar 2020 07:46:00 PM CST
# now runcron exited 

runcron runs under a supervisor. Here's a very simple supervisor:

while :; do ~/src/c/runcron/runcron  '*/10 * * * * *' date; done                                                                                      
Mon Mar 30 09:32:30 EDT 2020
Mon Mar 30 09:32:40 EDT 2020
Mon Mar 30 09:32:50 EDT 2020
Mon Mar 30 09:33:00 EDT 2020
Mon Mar 30 09:33:10 EDT 2020
Mon Mar 30 09:33:20 EDT 2020
^C

To run multiple cronjobs, use something like daemontools:

  • install daemontools
$ sudo apt install daemontools
  • create the service files
$ mkdir -p service/date17 service/date33

$ cat <EOF>service/date17/run
#!/bin/sh

exec runcron '*/17 * * * * *' bash -c 'echo 17: $(date)'
EOF

$ cat <EOF>service/date33/run
#!/bin/sh

exec runcron '*/33 * * * * *' bash -c 'echo 33: $(date)'
EOF

$ chmod +x service/*/run
  • run the supervised jobs
$ svscan service/
17: Mon Mar 30 09:36:17 EDT 2020
33: Mon Mar 30 09:36:33 EDT 2020
17: Mon Mar 30 09:36:34 EDT 2020
17: Mon Mar 30 09:36:51 EDT 2020
33: Mon Mar 30 09:37:00 EDT 2020
17: Mon Mar 30 09:37:00 EDT 2020
17: Mon Mar 30 09:37:17 EDT 2020
33: Mon Mar 30 09:37:33 EDT 2020
17: Mon Mar 30 09:37:34 EDT 2020
17: Mon Mar 30 09:37:51 EDT 2020
^C
commented

but this seems not work as described:

runcron supervises tasks:
if the tasks succeeds (exits 0), sleeps until the next cron interval

so, this is a feature of supervisor, not the the runcron.

runcron did not sleeps until the next cron interval,
it's the external script (like the example you gave) which sleep

the runcron program actually run:

if the tasks succeeds (exits 0), runcron exit with code 0

The supervisor restarts runcron, then runcron sleeps to the next cron interval. The supervisor doesn't sleep (note there isn't a sleep in the while :; do ...; done loop).

$ runcron -v "@yearly" date
now[1585579333]=Mon Mar 30 10:42:13 2020
next[1609477200]=Fri Jan  1 00:00:00 2021
now[1609477200]=Fri Jan  1 00:00:00 2021
next[1641013200]=Sat Jan  1 00:00:00 2022
last exit status was 0, sleep interval is 23897867s, command timeout is 31536000s
^C

If we interrupt runcron, the task is re-scheduled without running the job:

$ runcron -v "@yearly" date
now[1585579378]=Mon Mar 30 10:42:58 2020
next[1609477200]=Fri Jan  1 00:00:00 2021
now[1609477200]=Fri Jan  1 00:00:00 2021
next[1641013200]=Sat Jan  1 00:00:00 2022
last exit status was 0, sleep interval is 23897822s, command timeout is 31536000s
commented

I know what is a supervisor.

I think "if the tasks succeeds (exits 0), sleeps until the next cron interval" is not clear and confused.

it should be:
"if the tasks succeeds (exits 0), runcron exit with code 0,
and then with the help of the supervisor, the runcron got start again,
and runcron sleeps until the next cron interval"
runcron can not sleeps itself without a external executor (here the supervisor)

most crond program, even the simplist one like busybox crond implementation,
will sleep itself without the help of a supervisor.

thanks for you work.

I think maybe removing the dependency of the supervisor will make the program more simple to use.
especially when integrated with container.

@ttys3 got it, agreed, the description in the README is confusing. I'll update the README as you suggested.

Thanks for your help, very much appreciated!