Home > Linux > Highly available cron jobs

Highly available cron jobs

Travel in Stygian
The damned scream my name
Travel in Stygian
I can’t repent it’s too late
(Iced Earth – Travel in Stygian)

Cronjobs are mostly a node-specific tasks that have to run at regular intervals – like for example logrotate. You have to rotate and compress your logs regularly otherwise nodes would run out of space. But sometimes there are cron jobs that have to run once per a cluster of machines. Now, setting up that job only on one of the nodes can be a pain. That specific node will be different, which is a pain to automatize. Either we hack it manually or add another clause in automation tool of choice (Puppet, Chef). Neither approach is really satisfying. Here comes rcron to the rescue 🙂

rcron is a simple binary that runs other commands, similar to ‘time’. It’s purpose is to run the command only if state file says current node is active. Otherwise, whatever the command, it won’t be run. So, a typical cronjob looking something like:

10 10 * * * /usr/local/bin/my_precious

would get changed to:

10 10 * * * /usr/bin/rcron /usr/local/bin/my_precious

Rcron configuration file /etc/rcron/rcron.conf defines “state” file. State file is a simple text file which consists out of one o two key words: ‘active’ or ‘passive’. If ‘state’ file has a word active, then rcron will run commands run after it, if not, it will just exit and return 0 (success). So this makes it ideal intermediary step between classic cron and cron job. State file can be changed via some cluster-aware management like RHCS, so you can set up a fully HA cron service.

Advertisements
Categories: Linux Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: