Saturday, July 17, 2010

Cronjob On System Reboot!!

I know there are definitely some other reliable way that Linux Guru's use to bring services back online, once the server reboots. Most people also use rc.local a great way. One of them can be adding these to your init scripts, but to write to /etc/init.d you do need to be root.

There is this cool facility of crontab which even normal users can use. It was a news for me too sometime back that there is this alternative way of adding entries to your crontab file, using shortcuts. These shortcuts allow you to make entries that will match at particular times.

Out of those available - most popular is @reboot.

You can edit your crontab entry -

#Crontab -e

@reboot 'some-command'

I am not sure how many of your were 'wowed' with this feature of crontab, but today I am here to caution you of a couple of caveats here..

  1. First of all, it is NOT going to work when you have a system back online after crash or shutdown.
  2. secondly - If you are planning to run something basing apache with some script once your system reboots, probably something like - wget -O - http://localhost/notify.php it is not going to be a success. But yeah! if you want to send a notify email with some shell script basing sendmail server it will get through. Thats beacuse - in /etc/init.d/rc3.S "cron " is executed with priority 85, and Apache with priority 90.
So check the dependencies carefully, before you use @reboot.

But the unique qaulity of @reboot is that - while each of the other shortcuts, like (@yearly, @annually, @monthly, @weekly, @daily, @midnight, @hourly) has an equivalent mapping to the "normal" crontab format. (e.g. @daily is identical to (0 0 * * *"), @reboot is an exception and definitely helpful some time when you have a scheduled reboot of the server.

Now to skipfast or adopt, this has to be decided by our creative minds - and nothing there, that I can enforce ;-)


No comments:

Post a Comment

Why Database CI/CD?

Making the Database Part of Your Continuous Delivery Pipeline The database, unlike other software components and code or compiled co...