Debugging cron on Docker
I had the issue of cronjobs not working (correctly) on my Docker instances.
This is what I did to fix it:
- Set correct permissions:
chmod 0600 /etc/cron.d/cronjob
- Set correct owner:
chown root /etc/cron.d/cronjob
When it failed, I could not find the logs of why it failed.
In order to see the output of the failed cronjobs, I installed postfix
(because the output of cronjobs is being mailed) and I installed rsyslog
- Install postfix:
apt-get update; apt-get install -y postfix; mkfifo /var/spool/postfix/public/pickup; service postfix restart
- Install
rsyslog
:apt-get update; apt-get install -y rsyslog; rsyslogd &
Now, whenever a cronjob failed, I could find output in either two locations:
- In the syslog:
/var/log/syslog
- In the mail sent to root:
/var/mail/root