Linux – Problems getting Cron to run processes tagged @reboot for LDAP users

cronlinuxUbuntu

I have a lab of computers running Ubuntu 9.10. Most of the people who log on to these computers are users from an LDAP server, and not local users. We discovered that if an LDAP user has a crontab with an entry marked to be run @reboot, the command will not actually run upon the reboot of a machine.

I'm pretty sure that this is because the cron daemon starts before networking is fully up, so the crontabs of any LDAP users aren't loaded and run or checked for @reboot. In fact, cron will ignore LDAP users' crontabs entirely after a reboot until that user runs crontab -e again and saves, or until the cron daemon is rebooted.

We were able to fix one part of this problem by adding the following line to /etc/crontab:

@reboot root /bin/sleep 45 && /etc/init.d/cron restart

Thus, when cron starts back up upon a reboot, it waits for networking to get up, then restarts the cron daemon. That fixes the problem of crontabs not being read at all for LDAP users. However, since it's the cron daemon being restarted and not the computer, @reboot entries are ignored.

Is there a way for a user to make a command run upon restarting the daemon, rather than a reboot? Or is there a better solution to this overall problem?

Thanks.

Best Answer

Sounds like you have a race condition where cron is scanning its tabs and not finding a valid user for some of them because the network/LDAP server can't be reached -- You need to make sure your user list is accessible before cron starts up.

Try adjusting your RC sequence so cron is not started until after the network is fully up (either by re-arranging rc.d or marking in the cron script that it requires networking to be started first).

Related Topic