Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two identically configured CentOS 5 servers (possibly more in the future). I need to run a cron job on any one of them and that it'll run only on one of them.

I know about RedHat Cluster Suite (we use it on other servers), but it's a too big a gun to use for this task, plus it doesn't really behave well for less than three nodes.

Is there anything light-weight I can use for that?

The servers can communicate with each other directly. I suppose I can develope something over ssh or nrpe (two server which are already installed on these servers), but I was wondering whether there is something already available.

share|improve this question

2 Answers 2

For enterprise solutions you can use BMC Control-M. An open source alternative would be Job Scheduler

share|improve this answer
    
Thanks. Since what I need is for the job to run on one server OR the other, Job Scheduler sounds like it could do the job. –  Amos Shapira Nov 25 '11 at 2:39

This is pretty simple to do with a lockfile on a shared filesystem like NFS. I'm assuming however you don't have that setup.

Here's a few ideas that come to mind:

  1. Implement a lock on some shared resource, or something that both machines can access. For example, can they both write to some external network resource? Downside: lots of opportunities for race conditions I'm sure.

  2. Use the readhat DLM and access locking via perl DLM::Client. Downside: as you mention, might be more heavyweight than you want.

  3. Try the ruby lockserver Officer. Might be fun if you're in to ruby.

  4. Here's another perl distributed locking mechanism: IPC::Locker. Advantage: doesn't require you to set up another service like the linux kernel DLM.

  5. Use a messaging service like RabbitMQ to do locking. Again, probably pretty heavyweight.

I'm a perl programmer myself, so I'l probably try IPC::Locker first. I like the simplicity of that approach if you just have two servers.

share|improve this answer
    
Thanks. I knew there must be some ways to do that already out there. The Perl one looks the simplest to use (Perl is my personal "native language" too), except that it'll be tricky to setup an HA locker daemon. I'm also not sure about the details of how to go from "shared resource locking" to "make it run on only one server". Perhaps by checking some rsync'ed file after obtaining the lock I can make "the other node" skip an iteration. –  Amos Shapira Nov 25 '11 at 2:40
    
Yeah, setting up a locker daemon is annoying. I suppose you could run it on one of the two machines? Then of course you've got problems if that machine goes south. –  Phil Hollenback Nov 25 '11 at 3:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.