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_Name
  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
    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
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
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_Name

Enabling Cron Job Scripts

Enable all cron job scripts with the following command:

$ rhc cartridge start cron -a App_Name

Note

The cron commands affect all cron jobs. You cannot disable or enable individual cron jobs.