Cron(定时运行守护进程):修订间差异
Yucheng Hu(讨论 | 贡献) (以“{{Installing Moodle}} The Moodle 'cron' process is a PHP script (part of the standard Moodle installation) that must be run regularly in the background. The Moodle...”为内容创建页面) |
Yucheng Hu(讨论 | 贡献) 无编辑摘要 |
||
第1行: | 第1行: | ||
{{Installing Moodle}} | {{Installing Moodle}} | ||
Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个经常必须定时在后台运行。 | |||
Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。 | |||
'''重要:不要尝试忽略在你的 Moodle 站点中设置Cron(定时运行守护进程)。没有这个守护进程,你的站点将不会完全正常工作。''' | |||
一个特殊的程序(通常称为'cron')被用来定时运行 Moodle 脚本。Moodle 的定时运行脚本可以运行发送邮件,更新 Moodle 报表,RSS,完成活动,发布论坛消息和其他任务。因为不同的任务在 Moodle 系统中不是同时运行的,换句话说,这些任务不是同时被触发的,而是分时被触发的。 | |||
定时任务(运行 Moodle 脚本)是基于 Unix 系统的核心组件,这操作系统包括(Linux 和 OSX)。定时任务用户管理所有基于时间的服务。在 Widows 中,也有类似的功能,这个功能在 Windows 中被称为 Windows 任务计划,这个被设置用来按照时间计划来运行。 | |||
== | 如果你使用的是共享主机服务,你可以咨询你的服务管理员或者相关文档来配置定时任务。 | ||
实际上,计划任务包含当个命令行,这个命令行通常设置在系统中的 cron 激活列表中。在基于 Unix 的操作系统中,这个配置文件被配置在'crontab'中。 | |||
== 基本讨论 == | |||
See the later sections for your server type; this section contains some general background information. | See the later sections for your server type; this section contains some general background information. |
2013年8月21日 (三) 03:50的版本
Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个经常必须定时在后台运行。
Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。
重要:不要尝试忽略在你的 Moodle 站点中设置Cron(定时运行守护进程)。没有这个守护进程,你的站点将不会完全正常工作。
一个特殊的程序(通常称为'cron')被用来定时运行 Moodle 脚本。Moodle 的定时运行脚本可以运行发送邮件,更新 Moodle 报表,RSS,完成活动,发布论坛消息和其他任务。因为不同的任务在 Moodle 系统中不是同时运行的,换句话说,这些任务不是同时被触发的,而是分时被触发的。
定时任务(运行 Moodle 脚本)是基于 Unix 系统的核心组件,这操作系统包括(Linux 和 OSX)。定时任务用户管理所有基于时间的服务。在 Widows 中,也有类似的功能,这个功能在 Windows 中被称为 Windows 任务计划,这个被设置用来按照时间计划来运行。
如果你使用的是共享主机服务,你可以咨询你的服务管理员或者相关文档来配置定时任务。
实际上,计划任务包含当个命令行,这个命令行通常设置在系统中的 cron 激活列表中。在基于 Unix 的操作系统中,这个配置文件被配置在'crontab'中。
基本讨论
See the later sections for your server type; this section contains some general background information.
There are essentially two steps to implementing cron:
- identifying the correct command to run
- finding the right place on your system to put the command
Working out the Moodle cron command
Moodle has two different ways to deploy cron which use different scripts within the Moodle install. These are as follows...
- The CLI (command line interpreter) script. This will be at the path
/path/to/moodle/admin/cli/cron.php
If in doubt, this is the correct script to use. This needs to be run by a 'PHP CLI' program on your computer. So the final command may look something like/usr/bin/php /path/to/moodle/admin/cli/cron.php
You can (and should) try this on your command line to see if it works. - The web based script. This needs to be run from a web browser and will be accessed via a web url something like http://your.moodle.site/admin/cron.php. You can find command line based web browser (e.g. wget) so the final command may look like
/usr/bin/wget http://your.moodle.site/admin/cron.php
This has the advantage that it can be run from *anywhere*. If you can't get cron to work on your machine it can be run somewhere else.
Finding the right place to put the command
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.
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
$ crontab -u www-data -e
This will open an editor window. To run the cli cron script every 15 minutes, add the line:
*/15 * * * * /usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null
NOTE: the final >/dev/null sends all the output to the 'bin' and stops you getting an email every 15 minutes.
Setting up cron on your system
Choose the information for your server type:
- Cron with Unix or Linux- Cron services on various UNIX and Linux flavored operating systems.
- Cron with Windows OS - Cron services in 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
- Cron with web hosting services- Cron services in various web hosting examples.
Here are some more instructions for specific hosts (please check that these are up to date):
Using third party cron service
Besides using cron hosted on your own server, you may use third party cron service (usually called webcron):
- EasyCron - A webcron service provider that eliminates the need of crontab or other task schedulers to set cron job.
Cron settings in Moodle
There are settings within Moodle that control aspects of cron operation:
- Cron settings - Moodle cron process password and CLI settings
Remote 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
Using Moodle forum discussions:
- Cron - can someone give me a quick confirmation of function?
- Cronjob Question
- Slow cron : avoiding simultaneous cron
- Visibility of cron.php
- 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.