Ce contenu n'est pas disponible dans la langue sélectionnée.
11.13. Scheduling Cron Jobs
Procedure 11.4. To Enable Cron Support for an Application:
- Add the cron scheduler cartridge to an application:
rhc cartridge add cron -a App_Name
$ rhc cartridge add cron -a App_Namerhc cartridge add cron -a App_Name
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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
$ mkdir -p .openshift/cron/minutely $ echo 'date >> $OPENSHIFT_REPO_DIR/php/date.txt' > .openshift/cron/minutely/date.sh
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The example cron job appends a new line of date information to the$OPENSHIFT_REPO_DIR/php/date.txt
file every minute. - Commit the changes and push them to the remote repository:
git add .openshift/cron/ git commit -m "configuring cron jobs" git push
$ git add .openshift/cron/ $ git commit -m "configuring cron jobs" $ git push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Example 11.19. Verifying Cron Job Script Works Correctly
curl http://holy-roller.example.com/date.txt
$ 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
/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.
Disable all cron job scripts with the following command:
rhc cartridge stop cron -a App_Name
$ rhc cartridge stop cron -a App_Namerhc cartridge stop cron -a App_Name
Enable all cron job scripts with the following command:
rhc cartridge start cron -a App_Name
$ rhc cartridge start cron -a App_Namerhc cartridge start cron -a App_Name
Note