Cron jobs using Whenever with VM, Docker & Dokku
Took me forever to work this one out - ended up call the rails command instead via crontabs. I've also got a rails app uploaded on dokku with ubuntu on the digital ocean server. Trying to get the Whenever gem to work... it just doesn't. whenever -i
doesn't work.
Whenever doesn't actually create any new crontabs for the dokku environment. It's good for figuring out the Cron syntax though!
So this is how I got scheduled tasks to work in dokku:
- Manually create your own crontab via
sudo crontab -e
which will open it up in vi/vim
You can use sudo crontab -r
to remove it, or sudo crontab -l
to view current crontabs
- Add the following code to the new crontab
The below code will execute every 1 minute.
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
* * * * * /bin/bash -c 'dokku run appname rails r MyModel.run_something'
Make your environmental variables are equivalent to ones you have in the env
command
grep CRON /var/log/syslog
to see the output log for trouble shooting. You may have to install postfix viasudo apt-get install postfix
in order for Cron to send mail notification of errors otherwise you may get“(CRON) info (No MTA installed, discarding output)”
error from the syslog.cat /var/mail/root
to view the mail received from Cron - stating errors if a cronjob fails to work.
Hopefully that's helpful. That's what got me through at least!