Cron(定时运行守护进程):修订间差异

来自MoodleDocs
跳转至:导航、​搜索
 
(未显示同一用户的5个中间版本)
第27行: 第27行:


 下面是相关内容:
 下面是相关内容:
# 命令行脚本:命令行脚本在路径<pre>/path/to/moodle/admin/cli/cron.php</pre>如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:<pre>/usr/bin/php /path/to/moodle/admin/cli/cron.php</pre> 你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
# 命令行脚本:命令行脚本在路径<pre>/path/to/moodle/admin/cli/cron.php</pre>如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:<pre>/usr/bin/php /path/to/moodle/admin/cli/cron.php</pre>你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
# 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:'''http://your.moodle.site/admin/cron.php'''。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:<pre>/usr/bin/wget http://your.moodle.site/admin/cron.php</pre> 这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。
# 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:'''http://your.moodle.site/admin/cron.php'''。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:<pre>/usr/bin/wget http://your.moodle.site/admin/cron.php</pre>这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。


=== 找到放置你定时运行命令行的正确路径 ===
=== 找到放置你定时运行命令行的正确路径 ===


This really does depend on the system you are using and you should find and read the documentation for your platform or hosting. In most cases getting the Moodle cron to run consists of establishing the correct command (above) and then adding it, and the time to run the command, to some sort of file. This might be either through a specific user interface or by editing the file directly.
找到定时任务的放置路径和你使用的操作系统有很大的关系,请参考你的操作系统文档和主机文档。


If using the CLI version you also need to make sure that the cron process is run as the correct user. This is not an issue with the web version.
一般来说如果成功配置 Moodle 的定时任务正确运行,你需要考虑你的命令是否正确,然后将命令放置到正确的位置,希望运行任务的正确时间和一些文件。


Example... installing cron on Ubuntu/Debian Linux. Assuming logged in as root..
在进行修改的时候,你可能会有用户界面来进行编辑配置,也可能没有用户界面编辑配置,你需要使用字符环境来进行配置。


''use the crontab command to open a crontab editor window for the www-data user. This is the user that Apache (the web server) runs as on Debian based systems''
如果你使用命令行的方式来运行你的计划任务,你需要考虑用户的权限,用户是否具有正确的权限来运行这个命令,对于采用 Web 来运行的话,就没有用户权限的问题。
 
例如,在 Ubuntu/Debian Linux 系统中进行安装,你使用的是 root 用户。
 
'' www-data 用户使用 crontab 命令来打开一个 crontab 命令编辑窗口。这是应为 Apache (Web 服务器)使用这个用户来在 Debian 系统中运行''
<pre>
<pre>
$ crontab -u www-data -e
$ crontab -u www-data -e
</pre>
</pre>
''This will open an editor window. To run the cli cron script every 15 minutes, add the line:''
'' 这个将会打开一个编辑窗口。如果希望每15分钟来运行一次命令,请添加下面的内容:''
<pre>
<pre>
*/15 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php >/dev/null
*/15 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php >/dev/null
</pre>
</pre>
NOTE: the final '''>/dev/null''' sends all the output to the 'bin' and stops you getting an email every 15 minutes.
注意:命令的最后 '''>/dev/null''' 将所有命令的输出发送到'bin' 目录,同时阻止你每 15 分钟获得一个电子邮件。


== Setting up cron on your system ==
== 在你的系统中设置 Moodle Cron ==
  
  
Choose the information for your server type:
为你的服务器选择正确的信息:


*[[Cron with Unix or Linux]]- Cron services on various UNIX and Linux flavored operating systems.
*[[Moodle Unix 或者 Linux 的 Cron]] - 基于 UNIX Linux 的定时运行任务服务配置。
*[[Cron with Windows OS]] - Cron services in Windows
*[[Cron with Windows OS]] - Windows 的定时运行任务。
*''Apple OSX'' - use the built-in 'crontab' service which is exactly the same as [[Cron with Unix or Linux]]. However, you might want to do it the 'Apple way' using launchd - see [[Cron with MAC OS X]]
*''Apple OSX'' - 内建的 'crontab' 服务与 [[Moodle Unix 或者 Linux 的 Cron]] 完全一致。但是,你可能需要遵守 'Apple 的特定运行方式' 来运行,请查看[[Cron with MAC OS X]]
*[[Cron with web hosting services]]- Cron services in various web hosting examples.
*[[Cron with web hosting services]] - 一系列的虚拟主机定时运行任务。


Here are some more instructions for specific hosts (please check that these are up to date):
下面是一些特定主机的特定指南,请在使用之前确定这些信息是最新的版本,否则可能会导致配置错误:


*[[Cron on 1and1 shared servers]]
*[[Cron on 1and1 shared servers]]


== Using third party cron service ==
== 使用第三方 cron 服务 ==
  
 
Besides using cron hosted on your own server, you may use third party cron service (usually called webcron):
除了可以使用你自己服务器的 cron 服务之外,你还可以使用第三方的 crone 服务,这个服务可以通过调用 webcron 来实现:
 
*[http://www.easycron.com EasyCron] - 一个 webcron 服务提供商,通常用户实现 crontab 或者其他需要定时运行的任务。
 
=== Moodle 的 cron 设置===
 
在 Moodle 中有一些设置来控制 cron 的操作:


*[http://www.easycron.com EasyCron] - A webcron service provider that eliminates the need of crontab or other task schedulers to set cron job.
*[[Cron settings]] - Moodle cron 处理密码和命令脚本设置。


=== Cron settings in Moodle ===
=== 远程 cron===


There are settings within Moodle that control aspects of cron operation:
使用 '基于 web' 的 cron 版本,对于需要执行的 cron 任务放置到不同的机器上进行调用非常有效。


*[[Cron settings]] - Moodle cron process password and CLI settings
例如,调用 cron 定时任务的服务器是在 Unix 机器上可以调用 Moodle 的 web 页面,但是你的 Moodle 是部署在 Windows 服务器上的。


===Remote cron===
通过远程 cron 调用,我们可以实现跨平台的调用方式。
Using the 'web based' version of cron it is perfectly ok to place the cron process on a different machine to the Moodle server. For example, the cron service on a Unix server can invoke the cron web 'page' on a Windows based Moodle server.


==See also==
== 请参考==
* [http://en.wikipedia.org/wiki/Cron Wikipedia article on cron function]
* [http://en.wikipedia.org/wiki/Cron 维基百科中有关 cron 的介绍]


Using Moodle forum discussions:
使用 Moodle 论坛中有关的讨论:
*[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?]
*[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?]
*[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question]
*[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question]
*[http://moodle.org/mod/forum/discuss.php?d=97457 Slow cron : avoiding simultaneous cron]
*[http://moodle.org/mod/forum/discuss.php?d=97457 Slow cron : avoiding simultaneous cron]
*[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php]
*[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php]
*[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - this discussion explains a nice trick that can be very useful when you are experiencing problems with your Windows Scheduled Task and you need to log the output of the Scheduled Task to a log file.
*[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - 这个讨论解释了一个非常有用的小技巧,这个小技巧在你使用 Windows 的计划任务时,你希望 log 程序输出非常有效。
*[http://www.ossez.com/forum-54-1.html OSS 计算技术有关 Moodle 功能的讨论社区]


[[es:Cron]]
[[es:Cron]]
[[fr:Cron]]
[[fr:Cron]]
[[ja:Cron]]
[[ja:Cron]]

2013年8月24日 (六) 14:38的最新版本

Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个进程必须定时在后台运行。

Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。

重要:不要尝试忽略在你的 Moodle 站点中设置Cron(定时运行守护进程)。没有这个守护进程,你的站点将不会完全正常工作。

一个特殊的程序(通常称为'cron')被用来定时运行 Moodle 脚本。Moodle 的定时运行脚本可以运行发送邮件,更新 Moodle 报表,RSS,完成活动,发布论坛消息和其他任务。因为不同的任务在 Moodle 系统中不是同时运行的,换句话说,这些任务不是同时被触发的,而是分时被触发的。

定时任务(运行 Moodle 脚本)是基于 Unix 系统的核心组件,这操作系统包括(Linux 和 OSX)。定时任务用户管理所有基于时间的服务。在 Widows 中,也有类似的功能,这个功能在 Windows 中被称为 Windows 任务计划,这个被设置用来按照时间计划来运行。

如果你使用的是共享主机服务,你可以咨询你的服务管理员或者相关文档来配置定时任务。

实际上,计划任务包含当个命令行,这个命令行通常设置在系统中的 cron 激活列表中。在基于 Unix 的操作系统中,这个配置文件被配置在'crontab'中。

基本讨论

针对你使用的操作系统,请对应查看你后面的内容,这部分仅仅讨论一些的基本背景信息。

使用下面 2 步可以对守护进程进行一些有效的配置:

  1. 确定运行的正确命令行
  2. 在你的操作系统中找到正确的位置来存放这个命令

配置 Moodle cron 命令行工作

Moodle 可以使用2 个不同的方法来在你的系统中部署定时运行脚本。

下面是相关内容:

  1. 命令行脚本:命令行脚本在路径
    /path/to/moodle/admin/cli/cron.php
    如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:
    /usr/bin/php /path/to/moodle/admin/cli/cron.php
    你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
  2. 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:http://your.moodle.site/admin/cron.php。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:
    /usr/bin/wget http://your.moodle.site/admin/cron.php
    这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。

找到放置你定时运行命令行的正确路径

找到定时任务的放置路径和你使用的操作系统有很大的关系,请参考你的操作系统文档和主机文档。

一般来说如果成功配置 Moodle 的定时任务正确运行,你需要考虑你的命令是否正确,然后将命令放置到正确的位置,希望运行任务的正确时间和一些文件。

在进行修改的时候,你可能会有用户界面来进行编辑配置,也可能没有用户界面编辑配置,你需要使用字符环境来进行配置。

如果你使用命令行的方式来运行你的计划任务,你需要考虑用户的权限,用户是否具有正确的权限来运行这个命令,对于采用 Web 来运行的话,就没有用户权限的问题。

例如,在 Ubuntu/Debian Linux 系统中进行安装,你使用的是 root 用户。

为 www-data 用户使用 crontab 命令来打开一个 crontab 命令编辑窗口。这是应为 Apache (Web 服务器)使用这个用户来在 Debian 系统中运行

$ crontab -u www-data -e

这个将会打开一个编辑窗口。如果希望每15分钟来运行一次命令,请添加下面的内容:

*/15 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php >/dev/null

注意:命令的最后 >/dev/null将所有命令的输出发送到'bin'目录,同时阻止你每 15 分钟获得一个电子邮件。

在你的系统中设置 Moodle Cron

为你的服务器选择正确的信息:

下面是一些特定主机的特定指南,请在使用之前确定这些信息是最新的版本,否则可能会导致配置错误:

使用第三方 cron 服务

除了可以使用你自己服务器的 cron 服务之外,你还可以使用第三方的 crone 服务,这个服务可以通过调用 webcron 来实现:

  • EasyCron - 一个 webcron 服务提供商,通常用户实现 crontab 或者其他需要定时运行的任务。

Moodle 的 cron 设置

在 Moodle 中有一些设置来控制 cron 的操作:

远程 cron

使用 '基于 web' 的 cron 版本,对于需要执行的 cron 任务放置到不同的机器上进行调用非常有效。

例如,调用 cron 定时任务的服务器是在 Unix 机器上可以调用 Moodle 的 web 页面,但是你的 Moodle 是部署在 Windows 服务器上的。

通过远程 cron 调用,我们可以实现跨平台的调用方式。

请参考

使用 Moodle 论坛中有关的讨论: