关闭系统后,cron作业会如何处理? [英] What happens to cron jobs when system in shutdown?

查看:61
本文介绍了关闭系统后,cron作业会如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自crontab的手册页.

From man page of crontab.

      string         meaning
      ------         -------
      @daily         Run once a day, "0 0 * * *".
      @midnight      (same as @daily)

因此,如果系统始终在午夜关闭,则将永远不会执行作业@daily?指定我要每天执行一次此作业但不在乎一天中何时确切执行该作业的正确方法是什么?

So a job @daily will never be executed if the system is always shutdown at midnight? What is the proper way to specify that I want to run this job once daily but I don't care when exactly it is executed in a day?

推荐答案

该作业可能会运行,但可能无法完成.cron是通过守护程序实现的,因此它始终在运行.根据系统的关闭顺序,实际上cron可能会在关闭过程中的较晚时间发送关闭信号,因此安排在关闭开始的那一刻仍可能运行的作业.

The job may run, but probably won't complete. cron is implemented via a daemon, so it's always running. Depending on your system's shutdown order, cron may actually be sent the shutdown signal fairly late in the shutdown process, so jobs scheduled for the moment the shutdown started may still run.

例如如果关机确切地从00:00:00开始,但直到00:00:05(午夜之后5秒(,那么短时间运行的2秒作业)可能仍然有时间完成),才向cron发送kill信号

e.g. If the shutdown starts at 00:00:00 exactly, but doesn't get to sending cron a kill signal until 00:00:05 (5 seconds after midnight(, then a short running 2-second job may still have time to complete.

但是,如果作业所依赖的任何服务已经关闭或正在关闭,则不可能完成.例如,...该脚本对mysql服务器执行ping操作以获取一小部分数据...但是mysql在00:00:01关闭,并且您的脚本直到00:00:02才进入mysql部分.

However, if any services that job depends on have already been shutdown or are in the process of shutting down, then it's unlikely to be able to finish. e.g.... the script pings a mysql server for one little piece of data... but mysql shut down at 00:00:01 and your script didn't get to the mysql portion until 00:00:02.

tl; dr:这是一个竞争条件,您的工作可以执行,但可能不会执行.

tl;dr: it's a race condition and your job MAY execute, but probably won't.

这篇关于关闭系统后,cron作业会如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆