2

Say I scheduled a task for time t2 in future t1 < t2 < t3

What if server get crashed at time t1. Will the task scheduled to execute at t2, still executes, if servers restarts before time t2 ( t1 < t < t2 ) ?

What if server crashes at t1 and restarts at t3 and say, server was down at t2. Will the task, that was scheduled for t2, get executed, if server restarts at t3 ( > t2 )

In shirt, does cron keeps a persistent record of tasks to be performed, in case server crashed or was down during scheduled time

chirag jain
  • 419
  • 4
  • 12
  • As long as: the server is up and cron daemon is running before and during time T, the task scheduled for time T will run at time T, so ur first scenario, server restarts before t2, t2 will still run. The second, server restarts at t3, no, t2 will not run – chiliNUT Mar 10 '18 at 08:04

2 Answers2

2

When the server is brought back up, crons will continue to execute at their regularly scheduled times.

Crons aren’t retroactively run; it wouldn’t make sense for them to be. Suppose you have a cron which backs up the server at midnight while everyone is at home asleep. If the server crashes at 11pm, and it’s restarted the next morning, you wouldn’t want the backup to automatically start running while everyone is trying to do their work.

Blair Fonville
  • 908
  • 1
  • 11
  • 23
1

In short: No. Cron simply executes tasks at their scheduled time. If the server is down, no tasks are executed.

Likewise, if you mess around with the system clock, cron would still execute tasks accordingly.

Zoon
  • 1,068
  • 2
  • 11
  • 26
  • that means i will have to keep a persistent record of all the tasks. I wrote a scheduler. If in case server get crashed, it will check all the tasks, whose time had passed and will execute them, and if not, schedule them again for future – chirag jain Mar 10 '18 at 08:03
  • 1
    Depending on your use-case, it is common to use cron to call your own task manager every minute. Your own task manager then uses some logic (last executed timestamp, etc.) to determine, if anything, what to execute. – Zoon Mar 10 '18 at 08:05