The OpenShift forums have been retired, but you can still read and search them.
For the most up-to-date information about how to use OpenShift please visit

Cron questions


I have some questions about the cron cartridge and would be happy, if someone please can give me some advice.

1) I would like to run a job every day at the time of 22:30. Is this possible? How do I have to configure this?

2) Is there a timeout limit?

3) Can I call a Java command line programm? Where do I have to place the java archive?

Regards, Lars


Thank you for your interest in OpenShift!

1) cron jobs: After adding the cron cartridge to your app, review {appName}/.openshift/cron/README.cron. You can create a job in {appName}/.openshift/cron/daily/. for what you want to do. Add it to your git repo, commit and push it to remote where it will get executed.

2) There shouldn't be a timeout. Let us know if you have any issues

3) You can write your job in any language, and you can call java from there as well. Try to ssh onto your gear and run: > java -version You can store your jar file anywhere in your git repo and call it with: > java $OPENSHIFT_REPO_DIR/src/...

HTHs; ~Nam

Correction on 2) -- there is a default timeout of 5 minutes on the top level script. So if you need something to run for longer, you can just start it nohupped and backgrounded ala:

nohup /path-to/some-other-script > $OPENSHIFT_LOG_DIR/logfile 2>&1 &

Thanks for catching that ramr!!

Hello Nam,

thank you for your answers!

But there is still one open detail for me: how can I specify a time for a daily job? I'm sorry, but I do not see, how this can be configured.

I realy need to be sure that the job will be started at 10:30pm. (+/- 5 minutes would be acceptable)

Regards, Lars

I'll be playing around with this today based on

Something to be mindful about is the system time on your gear relative to when you want to run your cron job. You will want to ssh in and run the "date" command:

Any update on this Nam? Should I SSH into my gear and then manually set the time at which i want to run my script?

I would like to run the script every 4 hours.

@ashwin.patti, couple of different ways of doing it:

  1. For your specific case, just create an hourly cron job that checks if $(($(date +%H) % 4)) is equal to 0 and if so, run your script.
  2. For a more specific case, if you want to say run it every 'n' seconds, you can just store the last run time into a file
    ala date +%s > $OPENSHIFT_DATA_DIR/last_run and then check if the current time is 'n' seconds ahead of the last run time.


Thanks for the suggestion, I am currently doing first way but would check out the second one too.

How about this in the minute cron:

if [ ! -f $OPENSHIFT_DATA_DIR/last_run ];
    touch $OPENSHIFT_DATA_DIR/last_run
    do something....
 if [[ $(find $OPENSHIFT_DATA_DIR/last_run -mmin +4) ]]; then #run every 5 mins
   run something....
   rm -f $OPENSHIFT_DATA_DIR/last_run
   touch $OPENSHIFT_DATA_DIR/last_run

Summarize: Can I create cron job with console? I can create cron job only in .openshift/cron/...? My app need create custom dynamic cron jobs, so I can not use Openshift server for this app??

@kriska, not via the console today. But you should be able to write your dynamic jobs via your app
say to a directory that persists across git pushes (e.g. $OPENSHIFT_DATA_DIR/custom_jobs/)
and then have a script in your .openshift/cron/... that just sources/runs the jobs in your custom jobs
directory $OPENSHIFT_DATA_DIR/custom_jobs/.


Is there still a 5 minut timeout for running cron jobs? I have a job that needs to run for hours (source sleeps for a few seconds after each request) My code in .openshift/cron/daily whould be something like this:

#/var/lib/openshift/uuid/python/virtenv/bin/python /var/lib/openshift/uuid/app-root/runtime/repo/myapp/ run_job

Should I use nohup as well?

Yes. As per @ramr above:
there is a default timeout of 5 minutes on the top level script. So if you need something to run for longer, you can just start it nohupped and backgrounded ala:

nohup /path-to/some-other-script > $OPENSHIFT_LOG_DIR/logfile 2>&1 &

Can someone give me a right answer how to do cron on openshift with django enviroment?

Putting the files in the cron directory is correct. Make sure it's set as executable, and that you can ssh into the server and run it from the command line. If it doesn't work like that, it def will not work when the cron runs. We'd need to see the code to be able to help determine why it won't run, but like I said, try running it from the command line on OpenShift first and see what it does.

hi, sorry for late reply, I thought I had email notifications. My bad. I have chmod 777 on my files in .openshift/cron/... Of course I tried to run that command from command line. I run it like it's mentioned in the file. example: /var/lib/openshift/500024/python/virtenv/bin/python /var/lib/openshift/500024/app-root/runtime/repo/wsgi/digrin/ crontab run 01cf5c08eb3017a88cdaabf52561fa2b error: TypeError: 'NoneType' object has no attribute 'getitem' If I login to shell, import module my_app.cron and run crons in shell, it works ok. So I guess there must a problem with cron app. It worked before, I have changed main app name since then. I also moved app from python 2.6 to python 2.7, so app has new name as well.

Ok, I've got it. I think problem was renaming default app, since cron was run from there. When I genereted cron on my local machine, it gave those commands different hashes. I knew on openshift I did not have permission to generate crons, so I copied those from localhost. It did work before, not after I change default app name. So I tried generating crons directly on openshift. Crons did not save because of permissions, but I was able to see correct hashes. It works with them. Thanks for help!

Glad that works, changing your application around can cause issues with external scripts for sure.