此内容没有您所选择的语言版本。

11.13. Scheduling Cron Jobs


Cron jobs for applications are created with the OpenShift Enterprise cron scheduler. This is done by adding the cron scheduler cartridge to an application, adding the required cron jobs to the appropriate directories, and then updating the remote Git repository.
The following instructions describe how to enable cron support for an application. It is assumed the application has already been created.

Procedure 11.4. To Enable Cron Support for an Application:

  1. Add the cron scheduler cartridge to an application:
    $ rhc cartridge add cron -a App_Namerhc cartridge add cron -a App_Name
    Copy to Clipboard Toggle word wrap
  2. Add the cron jobs to the application's .openshift/cron/{minutely,hourly,weekly,daily,monthly}/ directories.

    Example 11.18. Sample Cron File

    $ mkdir -p .openshift/cron/minutely
    $ echo 'date >> $OPENSHIFT_REPO_DIR/php/date.txt' > .openshift/cron/minutely/date.sh
    Copy to Clipboard Toggle word wrap
    The example cron job appends a new line of date information to the $OPENSHIFT_REPO_DIR/php/date.txt file every minute.
  3. Commit the changes and push them to the remote repository:
    $ git add .openshift/cron/
    $ git commit -m "configuring cron jobs"
    $ git push
    Copy to Clipboard Toggle word wrap
Verify that the cron job script you create works correctly.

Example 11.19. Verifying Cron Job Script Works Correctly

For the script used in the example, it can be verified with the following command:
$ curl http://holy-roller.example.com/date.txt
Thu Feb  2 01:02:01 EST 2012
Thu Feb  2 01:03:01 EST 2012
Thu Feb  2 01:04:01 EST 2012
Copy to Clipboard Toggle word wrap
The scripts placed in the /cron subdirectories are executed at the respective frequencies. For example, scripts in each subdirectory are executed in alphabetical order; scripts in the /cron/hourly directory are executed on the first minute of every hour.
Disabling Cron Job Scripts

Disable all cron job scripts with the following command:

$ rhc cartridge stop cron -a App_Namerhc cartridge stop cron -a App_Name
Copy to Clipboard Toggle word wrap

Enabling Cron Job Scripts

Enable all cron job scripts with the following command:

$ rhc cartridge start cron -a App_Namerhc cartridge start cron -a App_Name
Copy to Clipboard Toggle word wrap

Note

The cron commands affect all cron jobs. You cannot disable or enable individual cron jobs.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat