So, we set up a project on a new Digital Ocean droplet and the cron jobs started failing.
Not just that, the log file that we had set up to track the cron was showing up empty!
After a lot of head scratching, I had a look at
And I noticed that I kept getting an output like this –
Jan 8 06:27:02 staging CRON: (CRON) info (No MTA installed, discarding output)
Searching for the anser I came across this AskUbuntu reply. The suggestion was to install
sudo apt-get install -y postfix
Did that. However, the logs were still empty!
Essentially, there were TWO problems.
When cron jobs are run, mails get sent. Per the Postfix page, it is a mail server which sends mail. Since
postfix wasn’t installed, these mails were not getting sent.
postfix, especially if it’s being used only for crons, it should be installed with the
So, now the mails were getting sent (to the user who’s set up the cron). That solved half of the first problem. Because, now it meant, there was something wrong with the program and I needed to see the mail to be able to figure that out.
The next step was to be able to read the mail to figure out what the problem was.
For this, I needed to install
sudo apt-get install -y mailutils
And finally, to read the mail, using
There’s a bunch of
Finally, reading the mail, I realized the second, and the actual problem –
The cron program (a ruby program) was getting run without being given the path to the root folder of the application and therefore was not able to find the
Gemfile and hence not able to load the Ruby Gems, since the first line in the cron was –
So, the solution to that was to wrap that command up in a
Dir.chdir to get to the application root folder.
app_root = File.expand_path(File.join(File.dirname(__FILE__), '../../..')) Dir.chdir app_root do Bundler.require end