New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dokku and cron jobs #450

Closed
vladimirnani opened this Issue Feb 10, 2014 · 10 comments

Comments

Projects
None yet
7 participants
@vladimirnani

vladimirnani commented Feb 10, 2014

Is there a possibility to manage a cron jobs using dokku?

@plietar

This comment has been minimized.

Show comment
Hide comment
@plietar

plietar Feb 10, 2014

Contributor

In dokku no.
However, you can setup cron jobs on the host, and run dokku run <app> <COMMAND>to execute your task in the container.

Contributor

plietar commented Feb 10, 2014

In dokku no.
However, you can setup cron jobs on the host, and run dokku run <app> <COMMAND>to execute your task in the container.

@plietar plietar closed this Feb 10, 2014

@plietar plietar added the question label Feb 10, 2014

@vladimirnani

This comment has been minimized.

Show comment
Hide comment
@vladimirnani

vladimirnani commented Feb 10, 2014

Thanks.

webcracy added a commit to webcracy/dokku that referenced this issue Oct 14, 2014

add exec command
Use the `exec` command to run commands in a non-interactive environment.

Makes it easier to run cron tasks for example. (cf. #450 and #451).
@motin

This comment has been minimized.

Show comment
Hide comment
@motin

motin Oct 29, 2014

Contributor

It should also be viable to use a hosted cron service or even roll your own using heroku's scheduler. The only requirement is that the cron service can run ssh commands using public key authentication.

Contributor

motin commented Oct 29, 2014

It should also be viable to use a hosted cron service or even roll your own using heroku's scheduler. The only requirement is that the cron service can run ssh commands using public key authentication.

@Zren

This comment has been minimized.

Show comment
Hide comment
@Zren

Zren Jul 25, 2015

NOTICE

If you use dokku run <app> <command> inside cron, make sure to use the --rm-container (or --rm) flag to automatically remove the container afterwards (like so dokku --rm run <app> <command>. Otherwise you'll find yourself running out of disk space.

You can notice the exited, but not deleted, containers with docker ps -a.

Zren commented Jul 25, 2015

NOTICE

If you use dokku run <app> <command> inside cron, make sure to use the --rm-container (or --rm) flag to automatically remove the container afterwards (like so dokku --rm run <app> <command>. Otherwise you'll find yourself running out of disk space.

You can notice the exited, but not deleted, containers with docker ps -a.

@henrik

This comment has been minimized.

Show comment
Hide comment
@henrik

henrik Aug 25, 2015

Contributor

Thank you, @Zren. Other things that are good to know (I just set this up):

You may need to specify the full path to dokku. I did which dokku to find out mine is at /usr/local/bin/dokku. Thus, my crontab entry has /usr/local/bin/dokku --rm run my-app my-command.

If it still doesn't work, make sure cron mails you any STDOUT or STDERR output. That helps a lot. It doesn't need to go to a "real" email address. I did sudo apt-get install postfix, chose "Local" during setup, then sudo tail -f /var/mail/root (replace "root" with another username if applicable) to read the errors once cron had attempted to run the job. If you want to stop getting those mails later, pipe output to /dev/null in your crontab line.

Contributor

henrik commented Aug 25, 2015

Thank you, @Zren. Other things that are good to know (I just set this up):

You may need to specify the full path to dokku. I did which dokku to find out mine is at /usr/local/bin/dokku. Thus, my crontab entry has /usr/local/bin/dokku --rm run my-app my-command.

If it still doesn't work, make sure cron mails you any STDOUT or STDERR output. That helps a lot. It doesn't need to go to a "real" email address. I did sudo apt-get install postfix, chose "Local" during setup, then sudo tail -f /var/mail/root (replace "root" with another username if applicable) to read the errors once cron had attempted to run the job. If you want to stop getting those mails later, pipe output to /dev/null in your crontab line.

@josegonzalez

This comment has been minimized.

Show comment
Hide comment
@josegonzalez

josegonzalez Aug 25, 2015

Member

@henrik would be great if you could contribute some docs on getting cronjobs running. I'm sure other users would benefit from doing so :)

Member

josegonzalez commented Aug 25, 2015

@henrik would be great if you could contribute some docs on getting cronjobs running. I'm sure other users would benefit from doing so :)

@henrik

This comment has been minimized.

Show comment
Hide comment
@henrik

henrik Aug 26, 2015

Contributor

@josegonzalez That's a good idea! I'll consider it. Would be nice to contribute back :)

Contributor

henrik commented Aug 26, 2015

@josegonzalez That's a good idea! I'll consider it. Would be nice to contribute back :)

@felixyz

This comment has been minimized.

Show comment
Hide comment
@felixyz

felixyz Aug 31, 2015

@henrik Alternatively (?), one can put this at the top of ones crontab file:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

felixyz commented Aug 31, 2015

@henrik Alternatively (?), one can put this at the top of ones crontab file:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@felixyz

This comment has been minimized.

Show comment
Hide comment
@felixyz

felixyz Sep 9, 2015

Mostly for the sake of documentation for others looking to do this, here is some notes about my setup:

  • Like @henrik, I configured cron to email me with output from jobs (in my case, I want actual emails sent so I get warnings if anything fails)
  • However, since I only want to hear from cron if something goes wrong, I installed cronic and run my (Ruby rake) jobs like this:
    */10 * * * * cronic dokku --rm run my-app bundle exec rake schedule_stuff
    I now get emails if the job fails, but not otherwise.
  • Another point discussed above is whether you need to invoke dokku with a full path. In my experience, setting up the cron jobs as the dokku user, I needed a fully qualified path, but as root (and extending the path as described in my previous comment) I didn't. Not sure what is recommended?

Nothing fancy, but might save someone else a bit of experimentation.

felixyz commented Sep 9, 2015

Mostly for the sake of documentation for others looking to do this, here is some notes about my setup:

  • Like @henrik, I configured cron to email me with output from jobs (in my case, I want actual emails sent so I get warnings if anything fails)
  • However, since I only want to hear from cron if something goes wrong, I installed cronic and run my (Ruby rake) jobs like this:
    */10 * * * * cronic dokku --rm run my-app bundle exec rake schedule_stuff
    I now get emails if the job fails, but not otherwise.
  • Another point discussed above is whether you need to invoke dokku with a full path. In my experience, setting up the cron jobs as the dokku user, I needed a fully qualified path, but as root (and extending the path as described in my previous comment) I didn't. Not sure what is recommended?

Nothing fancy, but might save someone else a bit of experimentation.

@josegonzalez

This comment has been minimized.

Show comment
Hide comment
@josegonzalez

josegonzalez Feb 14, 2016

Member

Note: while dokku currently does not manage cron, we do have official documentation on how to use dokku in conjunction with cron here.

Member

josegonzalez commented Feb 14, 2016

Note: while dokku currently does not manage cron, we do have official documentation on how to use dokku in conjunction with cron here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment