每次添加或修改新计划后是否需要重新启动 cron 或 crond?

pre*_*ise 33 cron

当我安排工作时,有些似乎立即应用,而另一些则在重新启动后应用。那么是否建议在添加新的 cron 作业后重新启动cron( crond) ?如何正确地做到这一点(尤其是在 Debian 系统中),即使对于普通用户来说,也应该使用sudo(例如sudo service cron restart)来做到这一点?

我试过:

/etc/init.d/cron restart
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用(也不起作用/etc/init.d/cron stopservice cron stop)并以返回代码 1 完成。

这是消息输出的一部分:

由于您尝试调用的脚本已转换为 Upstart 作业,您还可以使用 stop(8) 实用程序,例如 stop cron stop: Rejected send message, 1 matching rules; type="method_call", sender=":1.91" (uid=1000 pid=3647 comm="stop cron ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requests_reply="0" 目的地="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

(这意味着什么?)

Tim*_*imo 25

不,您不必重新启动cron,它会注意到您的 crontab 文件(/etc/crontab或用户 crontab 文件)的更改。

在你的 /etc/crontab 的顶部你可能有(如果你有cron那个 IIRC的 Vixie 实现是 Debian 上的):

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
Run Code Online (Sandbox Code Playgroud)

您可能看不到已实施的特定更改的原因是,如果您向 eg 添加了内容/etc/cron.daily并且已经发生了日常运行。

您得到的消息是因为您使用了一种旧的方式在系统上重新启动 cron。推荐的方法(但如果您只是编辑 cron 文件则不需要)是:

 restart cron
Run Code Online (Sandbox Code Playgroud)

您当然必须重新启动才能看到@reboot cron 作业的效果